Java Reference
In-Depth Information
• The
Customer
and
Address
entity classes. These classes model the data of the
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
details.
• The
CustomerClientXML
and
CustomerClientJSON
client classes. These
classes test the resource methods of the web service using XML and JSON repres-
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
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;