Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.1
-
Fix Version/s: 1.3.3
-
Labels:None
-
Number of attachments :
Description
When there is an element that contains a list of elements in it, and those sub-elements contain a list of items as their last elements, fields from the first, outer object are incorrectly placed inside the nested array.
Take the following xsd file:
<xs:element name="SearchResult">
<xs:complexType>
<xs:sequence>
<xs:element name="results" type="Type1" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="totalMatches" type="xs:int" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="Type1">
<xs:annotation>
<xs:documentation>A type that has an unbound list of elements for its last type</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element name="fieldA2" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
The SearchResult object contains just 2 fields: a "results" field (list) and a single "totalMatches" field (int). The "results" themselves contain a list of strings.
When creating these objects and marshalling them to json, the "totalMatches" field is incorrectly placed inside the list of "results".
The xml version is:
<SearchResult>
<results>
<fieldA2>field00</fieldA2>
<fieldA2>field01</fieldA2>
</results>
<results>
<fieldA2>field10</fieldA2>
<fieldA2>field11</fieldA2>
</results>
<totalMatches>2</totalMatches>
</SearchResult>
But the JSON version is:
{"SearchResult":{"results":[
,
{"fieldA2":["field10","field11"]},2]}}
or (formatted)
{
"SearchResult":{
"results":[
,
,
2
]
}
}
Note how there is no "totalMatches" text in the response, and the value "2" is placed as an element in the "results" array.
Adding another field so that a list is not the last element of the inner object prevents the problem.