background image

Identical schema content

<< Define schema element | j2s-xmlAdapter-field Example >>
<< Define schema element | j2s-xmlAdapter-field Example >>
68
U
SING
JAXB
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 @XmlAc-
cessorOrder 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>
The purchase order code example demonstrates the affects of schema content
ordering using the @XmlAccessorOrder annotation at the package and class
level, and the @XmlType.propOrder annotation on a class.
Class
package-info.java
defines @XmlAccessorOrder to be ALPHABETI-
CAL for the package. The public fields
shipTo
and
billTo
in class
Purchase-