background image

j2s-xmlAdapter-field Example

<< Identical schema content | The XmlAdapter interface >>
<< Identical schema content | The XmlAdapter interface >>
J
2
S
-
XML
A
DAPTER
-
FIELD
E
XAMPLE
69
OrderType
will be affected in the generated schema content order by this rule.
Class
USAddress
defines the @XmlType.propOrder annotation on the class.
This demonstates user-defined property order superseding ALPHABETICAL
order in the generated schema.
The generated schema file can be found in directory
schemas
.
j2s-xmlAdapter-field Example
The j2s-xmlAdapter-field example demonstrates how to use the
XmlAdapter
interface and the @XmlJavaTypeAdapter annotation to provide a custom map-
ping of XML content into and out of a HashMap (field) that uses an "int" as the
key and a "string" as the value.
Interface
XmlAdapter
and annotation @XmlJavaTypeAdapter are used for spe-
cial processing of datatypes during unmarshalling/marshalling. There are a vari-
ety of XML datatypes for which the representation does not map easily into Java
(for example,
xs:DateTime
and
xs:Duration
), and Java types which do not
map conveniently into XML representations, for example implementations of
java.util.Collection
(such as
List
) and
java.util.Map
(such as
HashMap
)
or for non-JavaBean classes. It is for these cases that
The
XmlAdapter
interface and the @XmlJavaTypeAdapter annotation are pro-
vided for cases such as these. This combination provides a portable mechanism
for reading/writing XML content into and out of Java applications.