What @XmlElements
is For
@XmlElements
corresponds to the choice
structure in XML Schema. A property corresponds to more than one element (see: http://blog.bdoughan.com/2010/10/jaxb-and-xsd-choice-xmlelements.html)
Collection Order
A JAXB implementation will honor the order the items have been added to the List
. This matches the behaviour you are seeing.
Getting the Desired Order
- You can add the items to the
List
in the order you want to see them appear in the XML document. - You can have separate properties corresponding to each element and then use
propOrder
on@XmlType
to order the output (see: http://blog.bdoughan.com/2012/02/jaxbs-xmltype-and-proporder.html) - Sort the
List
property on a JAXBbeforeMarshal
event.