background image

Running the XmlAdapter Field Example

<< HashMap Schema | Running the XmlAttribute Field Example >>
<< HashMap Schema | Running the XmlAttribute Field Example >>

Running the XmlAdapter Field Example

AdapterPurchaseListToHashMap
with field HashMap basket. This pairing will cause the
marshal/unmarshal method of AdapterPurchaseListToHashMap to be called for any
corresponding marshal/unmarshal action on KitchenWorldBasket.
Building and Running the XmlAdapter Field Example Using NetBeans
IDE
Follow these instructions to build and run the XmlAdapter Field example on your Application
Server instance using the NetBeans IDE.
1. In NetBeans IDE, select File
Open Project.
2. In the Open Project dialog, navigate to tut-install/javaeetutorial5/examples/jaxb/.
3. Select the j2s-xmlAdapter-field folder.
4. Select the Open as Main Project check box.
5. Click Open Project Folder.
6. Right-click the j2s-xmlAdapter-field project and select Run Project.
Building and Running the XmlAdapter Field Example Using Ant
To compile and run the XmlAdapter Field example using Ant, in a terminal window, go to the
tut-install/javaeetutorial5/examples/jaxb/j2s-xmlAdapter-field/ directory and type the
following:
ant runapp
XmlAttribute Field Example
The XmlAttribute Field example shows how to use the @XmlAttribute annotation to define a
property or field to be treated as an XML attribute.
The @XmlAttribute annotation maps a field or JavaBean property to an XML attribute. The
following rules are imposed:
A static final field is mapped to a XML fixed attribute.
When the field or property is a collection type, the items of the collection type must map to a
schema simple type.
When the field or property is other than a collection type, the type must map to a schema
simple type.
When following the JavaBean programming paradigm, a property is defined by a get and set
prefix on a field name.
Java-to-Schema Examples
Chapter 17 · Binding between XML Schema and Java Classes
543