JsonFromJaxb Example

This example demonstrates how to use JSON representation of JAXB based resources.

A simple web application is presented with two resources: a flight list and a aircraft type list. A client can obtain the former list or update it using XML or JSON representation. The second list is read-only and shows how to provide JSON array using List<JAXBBean> objects.

Contents

The flight list web resource is implemented by com.sun.jersey.samples.jsonfromjaxb.resources.FlightList class. The aircraft type list web resource is implemented by com.sun.jersey.samples.jsonfromjaxb.resources.AircraftTypeList class.

The mapping of the URI path space is presented in the following table:

URI path Resource class HTTP methods
/flights/ FlightList GET, PUT
/aircrafts/ AircraftTypeList GET

Running the Example

Run the example as follows:

mvn clean compile exec:java

This deploys the JSON from JAXB example using Grizzly

A WADL description may be accessed at the URL:

http://localhost:9998/jsonfromjaxb/application.wadl

Following steps are using cURL command line tool:

Get the list of flights in JSON format:

curl -HAccept:application/json http://localhost:9998/jsonfromjaxb/flights

Get the list of flights in XML format:

curl -HAccept:application/xml http://localhost:9998/jsonfromjaxb/flights

Get the list of aircraft types in JSON format:

curl -HAccept:application/json http://localhost:9998/jsonfromjaxb/aircrafts

You can also see test classes at src/main/test subdirectory for detail information how to consume the service using Jersey client API