I'm unmarshalling a sequence of elements with JAXB in a list, see below.
XML-File
<stroke>
<textPoint x="81.0" y="457.0" p="0.0" e="90.0" a="0.0" />
<textPoint x="80.0" y="457.0" p="0.0" e="89.0" a="135.0" />
<textPoint x="81.0" y="455.0" p="0.0" e="86.0" a="135.0" />
....
<textPoint x="228.0" y="475.0" p="0.0" e="57.0" a="122.0" />
<textPoint x="213.0" y="456.0" p="0.0" e="57.0" a="121.0" />
<textPoint x="233.0" y="476.0" p="0.0" e="57.0" a="122.0" />
</stroke>
Java-Code
private List<TextPoint> textPointList;
@XmlElement(name = "textPoint")
public List<TextPoint> getTextPointList() {
return textPointList;
}
public void setTextPointList(List<TextPoint> textPointList) {
this.textPointList = textPointList;
}
However, I'm a bit worried about the inherent order of the textPoint-elements, as they are ordered fine in the XML-file, but there is no element (e.g. ID) I could sort them via propOrder
. Nevertheless, it seems to unmarshal them fine in the same order as in the XML-file, so is there no need to worry about that?
The List
will be populated based on the order the elements appear in the XML on an unmarshal. When marshalling the order of the elements in the XML will be based on the order of the corresponding objects in the List
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With