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

前端 未结 1 675
渐次进展
渐次进展 2021-01-01 17:54

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?

相关标签:
1条回答
  • 2021-01-01 18:15

    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>
    
    0 讨论(0)
提交回复
热议问题