Convert List, Map to JSON in REST Response using Jersey

The most important concept in REST is resources, which are identified by global IDs — typically using URIs. Client applications use HTTP methods (GET/ POST/ PUT/ DELETE) to manipulate the resource or collection of resources. A RESTful Web service is implemented using HTTP and the principles of REST. Typically, a RESTful Web service should define the following aspects:

The base/root URI for the Web service such as http://<host>/<appcontext/contextpath>/<url pattern>/<resources>.
The MIME type of the response data supported, which are JSON/XML/TEXT/HTML etc.
The set of operations supported by the service. (for example, POST, GET, PUT or DELETE).


HTTP methods are mapped to CRUD (create, read, update and delete) actions for a resource. Although you can make slight modifications such as making the PUT method to create or update, the basic patterns are listed as follows.

HTTP GET: Get/List/Retrieve an individual resource or a collection of resources.
HTTP POST: Create a new resource or resources.
HTTP PUT: Update an existing resource or collection of resources.
HTTP DELETE: Delete a resource or collection of resources.


Eclipse, JDK 1.7, Maven 2.x, Jersey

Step 1. Create maven project in Eclipse with the below information

Group Id: com.roytuts
Artifact Id: rest-service

Step 2. Modify the pom.xml file to use jar libraries

Step 3. Modify web.xml file to use the jersey servlet

Step 4. Create a REST resource class as shown below

Step 5. Create utility class for data population

Step 6. Create a POJO class which defines Book

Step 7. Create Junit class for testing different REST operations

Step 8. Run the above test class, you will see the below output in the console

That’s all. Thanks for reading.

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.