I have an xml file which looks as follows:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Envelope>
<AttrA>aaa</AttrA>
<AttrB>bbb</AttrB>
<Element ID="1">elem1</Element>
<Element ID="2">elem2</Element>
...
<Element ID="n">elemn</Element>
</Envelope>
And a corresponding Java class:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"attrA",
"attrB",
"elements",
})
@XmlRootElement(name = "Envelope")
public class Envelope implements Serializable, Equals, HashCode, ToString {
@XmlElement(name = "AttrA", required = true)
protected AttrA attrA;
@XmlElement(name = "AttrB", required = true)
protected AttrB attrB;
@XmlElement(name = "Element")
protected List<Element> elements;
}
The unmarshalling works fine and I also get my elements-list populated with the appropriate elements, but sometimes the Elements are being swapped in the list. E.q. sometimes I get a list with element 1 and 2 swapped or elements 2 and 3 swapped their places. This affects the equals-method later on during the processing of the objects. I cannot figure out what exactly influences the insert order of the elements into the list.
Is there any anotation or some other way to define the insertion order of the elements? Does anybody see any other problems with my code?
Regards, Iryna.
No comments:
Post a Comment