Overview

This article describes how to get a JSON response from the RESTful web services using jersey implementation.Jersey will use Jackson to convert Java objects to/form JSON.Jackson ObjectMapper can parse JSON from a string, stream or file, and create a Java object or object graph representing the parsed JSON.Jersey will use this API to the marshaling [converting the objects] process.

Add ‘jersey-json.jar‘ to your Maven pom.xml which includes all Jackson and other JSON supporting libraries.

pom.xml

In web.xml add “com.sun.jersey.api.json.POJOMappingFeature” as “init-param”

web.xml

Customer.java

In the web service class, we need to annotate the method with @Produces(MediaType.APPLICATION_JSON). By doing so we are instructiong the service method that we are expecting the JSON output, thats it jersey will take care rest of the things.

JsonFromRestful.java

The application will start by hitting the following URL

http://localhost:8080/WebServices_JAX_RS/rest/users/200

That’s all for JSON response from the RESTful web services using jersey implementation, Hope you liked it. Keep Learning and Sharing 🙂 !!

It's good to share...Share on FacebookTweet about this on TwitterShare on LinkedInPin on PinterestShare on Google+Email this to someone

Leave a Reply

Your email address will not be published. Required fields are marked *