Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
owen777
Level 7

Default assocarray field's value

Hey, what's the correct way of setting default assocarray field's value in XML? Is there any? I'm able to set only an empty object via:
<field id="headers" type="assocarray" value="{}" />


but none of the following works:

<field id="headers" type="assocarray" value="{test: value}" />
<field id="headers" type="assocarray" value='{test: "value"}' />
<field id="headers" type="assocarray" value='{"test": "value"}' />
<field id="headers" type="assocarray" value="{test: \"value\"}" />
<field id="headers" type="assocarray" value="{\"test\": \"value\"}" />

I need to set such default value inside field's declaration because if I'm setting it in inside the init() function, from time to time, when trying to get "headers" field value right after object creation, it's Invalid.
0 Kudos
7 Replies
joetesta
Level 10

Re: Default assocarray field's value

Could you:

  •  set the value from the place where you are getting the headers or,

  •  put an invalid check with a reasonable fallback or,

  •  recheck on a timer?
aspiring
0 Kudos
owen777
Level 7

Re: Default assocarray field's value

@joetesta that would be a workaround. Hence it's not mentioned in the docs it's impossible to set default values for few specific types of a field, then it should be allowed. The question is how to do this.

If it's impossible, the docs should be updated. If Roku only moves its docs to a public repository, we could participate in updating them via pull requests, but obviously nobody from Roku will even answer this question, let alone open the docs.
0 Kudos
joetesta
Level 10

Re: Default assocarray field's value

sorry
aspiring
0 Kudos
Roku Employee
Roku Employee

Re: Default assocarray field's value

"owen777" wrote:
Hey, what's the correct way of setting default assocarray field's value in XML? Is there any? I'm able to set only an empty object via:
<field id="headers" type="assocarray" value="{}" />


but none of the following works:

<field id="headers" type="assocarray" value="{test: value}" />
<field id="headers" type="assocarray" value='{test: "value"}' />

...


To embed a double quotation mark (") in an XML attribute, you need to escape it as "&quot;"
E.g.
<field id="headers" type="assocarray" value="{myint: 123, mystr:&quot;abc&quot;}" />

should work to set headers = {myint:123, mystr:"abc"}
0 Kudos
owen777
Level 7

Re: Default assocarray field's value

"RokuKC" wrote:

To embed a double quotation mark (") in an XML attribute, you need to escape it as "&quot;"
E.g.
<field id="headers" type="assocarray" value="{myint: 123, mystr:&quot;abc&quot;}" />

should work to set headers = {myint:123, mystr:"abc"}

Not really:
<field id="headers" type="assocarray" value="{&quot;Content-Type&quot;: &quot;application/json&quot;, &quot;Accept&quot;: &quot;application/json&quot;}" />


breaks the app
0 Kudos
joetesta
Level 10

Re: Default assocarray field's value

I think assocarray can't have quoted key, did you try:
<field id="headers" type="assocarray" value="{Content-Type: &quot;application/json&quot;, Accept: &quot;application/json&quot;}" />
aspiring
0 Kudos
Roku Employee
Roku Employee

Re: Default assocarray field's value

"owen777" wrote:

Not really:
<field id="headers" type="assocarray" value="{&quot;Content-Type&quot;: &quot;application/json&quot;, &quot;Accept&quot;: &quot;application/json&quot;}" />


breaks the app


I confirm, that appears to be a bug in the RSG support. I've filed a ticket to report this.

Unfortunately "Content-Type" is not a valid unquoted identifier, so it can't be used in the XML field value as an AA key name without quoting.
0 Kudos