Java Reference
In-Depth Information
Click here to view code image
@Path("/product")
public class ProductService {
@GET
// ...
@POST
@Path("/create")
@Consumes("application/xml")
public Response createProduct(Product prod) {
// Process or store the product and return a response
// ...
}
}
Some IDEs, such as NetBeans IDE, will run the schema compiler tool automatically dur-
ing the build process if you add an .xsd file to your project sources. For a detailed ex-
ample, see “ Modifying the Example to Generate Entity Classes from an Existing Schema
on page 216 . The modified customer example contains a more hierarchical XML
schema definition, which results in a more complex relationship between the Java classes
that model the data.
Using JSON with JAX-RS and JAXB
JAX-RS can automatically read and write XML using JAXB, but it can also work
with JSON data. JSON is a simple text-based format for data exchange derived from
JavaScript. For the examples above, the XML representation of a product is:
Click here to view code image
<?xml version="1.0" encoding="UTF-8"?>
<product>
<id>1</id>
<name>Mattress</name>
<description>Queen size mattress</description>
<price>500</price>
</product>
The equivalent JSON representation is:
{
"id":"1",
"name":"Mattress",
"description":"Queen size mattress",
Search WWH ::




Custom Search