Java Reference
In-Depth Information
• The Customer and Address entity classes. These classes model the data of the
application and contain JAXB annotations. See The Customer and Address
Entity Classes ” on page 209 for details.
• The CustomerService resource class. This class contains JAX-RS resource
methods that perform operations on Customer instances represented as XML or
JSON data using JAXB. See “ The CustomerService Class ” on page 212 for
details.
• The CustomerClientXML and CustomerClientJSON client classes. These
classes test the resource methods of the web service using XML and JSON repres-
entations of Customer instances. See “ The CustomerClientXML and Cus-
tomerClientJSON Classes on page 214 for details.
The customer sample application shows you how to model your data entities as Java
classes with JAXB annotations. The JAXB schema generator produces an equivalent
XML schema definition file ( .xsd ) for your entity classes. The resulting schema is used
to automatically marshal and unmarshal entity instances to and from XML or JSON in the
JAX-RS resource methods.
In some cases you may already have an XML schema definition for your entities. See
Modifying the Example to Generate Entity Classes from an Existing Schema ” on page
216 for instructions on how to modify the customer example to model your data starting
from an .xsd file and using JAXB to generate the equivalent Java classes.
The Customer and Address Entity Classes
The following class represents a customer's address:
@XmlRootElement(name="address")
@XmlAccessorType(XmlAccessType.FIELD)
public class Address {
@XmlElement(required=true)
protected int number;
@XmlElement(required=true)
protected String street;
@XmlElement(required=true)
protected String city;
@XmlElement(required=true)
protected String state;
Search WWH ::




Custom Search