Java Reference
In-Depth Information
public
public String getFirstName () {
return
return firstName ;
}
public
public void
void setFirstName ( String firstName ) {
this
this . firstName = firstName ;
}
@XmlElement ( name = "last-name" )
public
public String getLastName () {
return
return lastName ;
}
public
public void
void setLastName ( String lastName ) {
this
this . lastName = lastName ;
}
@XmlElement
public
public String getStreet () {
return
return street ;
}
...
}
The JAXB annotations provide a mapping between the Customer class and XML.
You don't need to write a lot of code to implement the JAX-RS service because JAX-RS
already knows how to handle JAXB annotated classes:
src/main/java/com/restfully/shop/services/CustomerResource.java
@Path ( "/customers" )
public
public class
class CustomerResource
CustomerResource {
private
private Map < Integer , Customer > customerDB =
new
new ConcurrentHashMap < Integer , Customer >();
private
private AtomicInteger idCounter = new
new AtomicInteger ();
public
public CustomerResource () {
}
@POST
@Consumes ( "application/xml" )
public
public Response createCustomer ( Customer customer ) {
customer . setId ( idCounter . incrementAndGet ());
customerDB . put ( customer . getId (), customer );
System . out . println ( "Created customer " + customer . getId ());
return
return Response . created ( URI . create ( "/customers/" +
Search WWH ::




Custom Search