Is there a way to make this do the right thing?
If I have a schema like this:
<xs:element name="A">
<xs:complexType>
<xs:sequence>
<xs:element name="Foo" type="xs:string" minOccurs="1"
maxOccurs="1"/>
<xs:element name="Bar" type="xs:string" minOccurs="1"
maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ArrayOfA">
<xs:complexType>
<xs:sequence>
<xs:element ref="A" minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
and a REST method returning an ArrayOfA, I get structurally different
results depending on if there's one A or more than one A in the result:
$ curl http://localhost:2259/myService/single
{"s.ArrayOfA":{"s.A":{"s.Foo":"foo","s.Bar":"bar"}}}
$ curl http://localhost:2259/myService/multiple
{"s.ArrayOfA":{"s.A":[{"s.Foo":"foo1","s.Bar":"bar1"},
{"s.Foo":"foo2","s.Bar":"bar2"}]}}
In the first case, I get a Javascript object 'A' that has Foo and Bar
directly on it. In the latter, that same object is the array I was
expecting. So everywhere I get an object like this back from my
service, I have to explicitly check if it's the first or second case
and handle it slightly differently, rather than just iterating over A
even if it's an array with one element.
--Joe