Forum Discussion

owen777's avatar
owen777
Binge Watcher
8 years ago

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.

7 Replies

  • 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?
  • owen777's avatar
    owen777
    Binge Watcher
    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.
  • RokuKC's avatar
    RokuKC
    Roku Employee
    "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"}
  • owen777's avatar
    owen777
    Binge Watcher
    "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
  • 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;}" />
  • RokuKC's avatar
    RokuKC
    Roku Employee
    "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.