background image

Class Content Order

<< XmlAccessorOrder Example | Schema Content Ordering in the Example >>
<< XmlAccessorOrder Example | Schema Content Ordering in the Example >>

Class Content Order

The default content order for @XmlType.propOrder is {} or {""}, not active. In such cases, the
active @XmlAccessorOrder annotation takes precedence. When class content order is specified
by the @XmlType.propOrder annotation, it takes precedence over any active
@XmlAccessorOrder
annotation on the class or package. If the @XmlAccessorOrder and
@XmlType.propOrder(A, B, ...)
annotations are specified on a class, the propOrder always
takes precedence regardless of the order of the annotation statements. For example, in the code
below, the @XmlAccessorOrder annotation precedes the @XmlType.propOrder annotation.
@XmlAccessorOrder(AccessorOrder.ALPHABETICAL)
@XmlType(propOrder={
"name", "city"})
public class USAddress {
.
.
public String getCity() {return city;}
public void setCity(String city) {this.city = city;}
public String getName() {return name;}
public void setName(String name) {this.name = name;}
.
.
}
In the code below, the @XmlType.propOrder annotation precedes the @XmlAccessorOrder
annotation.
@XmlType(propOrder={
"name", "city"})
@XmlAccessorOrder(AccessorOrder.ALPHABETICAL)
public class USAddress {
.
.
public String getCity() {return city;}
public void setCity(String city) {this.city = city;}
public String getName() {return name;}
public void setName(String name) {this.name = name;}
.
.
}
In both scenarios, propOrder takes precedence and the identical schema content shown below
will be generated.
<xs:complexType name=
"usAddress">
<xs:sequence>
<xs:element name=
"name" type="xs:string" minOccurs="0"/>
<xs:element name=
"city" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
Java-to-Schema Examples
Chapter 17 · Binding between XML Schema and Java Classes
539