Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell JAXB that order of elements does not matter?

Tags:

java

jaxb

xsd

Is it possible to tell JAXB to ignore the order of elements? So that the generate XSD will contain all-elements instead of sequence-elements?

like image 829
Christian Strempfer Avatar asked Jan 17 '11 11:01

Christian Strempfer


1 Answers

Add an XmlType annotation to the class with an empty propOrder, like this:

@XmlType(propOrder={})
public class MyClass{
    String username;
    String street;
    String address;
}

It will then generate an xs:all (which is unordered) instead of a sequence.

<xs:complexType name="MyClass">
  <xs:all>
    <xs:element name="username" type="xs:string" minOccurs="0"/>
    <xs:element name="street" type="xs:string" minOccurs="0"/>
    <xs:element name="address" type="xs:string" minOccurs="0"/>
  </xs:all>
</xs:complexType>
like image 136
dogbane Avatar answered Nov 25 '22 16:11

dogbane