Show Topics
Hide Topics

 JAX-RS JSON Example Using Jersey


Jersey uses Jackson to convert object to / form JSON. In this example, we show you how to convert a “user” object into JSON format, and return it back to user


1.Create Dynamic web project in eclipse, convert that into Maven Project



2.Configure pom.xml

To make Jersey support JSON mapping, declares “jersey-json.jar” in Maven pom.xml file.




3.Configure web.xml

In web.xml, declares “com.sun.jersey.api.json.POJOMappingFeature” as “init-param” in Jersey mapped servlet. It will make Jersey support JSON/object mapping.



4.Write “UserBo” class

Write “UserBo” class object, Jersey will convert this object into JSON format.



5.Create RESTFul webservice Jersey

Annotate the method with @Produces(MediaType.APPLICATION_JSON). Jersey will use Jackson to handle the JSON conversion automatically.



6.Test Webservice directly by using URL / writing webservice client



Download Example Code