background image

j2s-xmlType Example

<< j2s-xmlRootElement Example | The factoryMethod >>
<< j2s-xmlRootElement Example | The factoryMethod >>
74
U
SING
JAXB
of XML built-in type
gMonthDay
. This relationship was defined on the package
in the file
package-info.java
. Field
shipDate
in file
TrackingOrder
is also
defined to be of type
XMLGregorianCalendar
, but the @XmlSchemaType anno-
tation statements override the package definition and specify the field to be of
type
date
. Property method
getTrackingDuration
defines the schema element
to be defined as primitive type
duration
and not Java type
String
.
j2s-xmlType Example
The j2s-xmlType example demonstrates the use of annotation @XmlType.
Annotation @XmlType maps a class or an enum type to a XML Schema type.
A class must have either a public zero arg constructor or a static zero arg factory
method in order to be mapped by this annotation. One of these methods is used
during unmarshalling to create an instance of the class. The factory method may
reside within in a factory class or the existing class. There is an order of presed-
ence as to which method is used for unmarshalling.
· If a factory class is identified in the annotation, a corresponding factory
method in that class must also be identified and that method will be used.
· If a factory method is identified in the annotation but no factory class is
identified, the factory method must reside in the current class. The factory
method is used even if there is a public zero arg constructor method
present.
· If no factory method is identified in the annotation, the class must contain
a public zero arg constructor method.