How can I avoide XSD sequence when generating XSDs

2019-07-22 00:41发布

When I have annotaded java class like

@javax.xml.bind.annotation.XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class UserdataType {

    String username;
    String street;
    String address;

it will be generated to

<xs:complexType name="userdataType">
<xs:sequence>
<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"/>

So, by default JAX-WS always generates 'sequences' in XSD files.

This forces the clients to take care of the exact order the elements, which is not helpful in some cases.

Is there a way to generate something different then sequences?

1条回答
做个烂人
2楼-- · 2019-07-22 01:20

Add an XmlType annotation with an empty propOrder, like this:

 @XmlType(propOrder={})

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

<xs:complexType name="userdataType">
  <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>
查看更多
登录 后发表回答