Publish Your Article Here

How to input json request with Jersey and Jackson?

In this page you will see support for Json using Jersey and Jackson APIs. Jackson is is a multi-purpose Java library for processing JSON data format. Jackson aims to be the best possible combination of fast, correct, lightweight, and ergonomic for developers In this example we will send json as a input, and the json request will be mapped to Order object.

Here is the pom.xml file. You need jersey-json jar file.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" 

Web.xml file for your reference. In web.xml add “com.sun.jersey.api.json.POJOMappingFeature” as “init-param” which supports Json object mapping.

<web-app id="WebApp_ID" version="2.4"

Our model class Order is annotated with required jackson annoations to support json transformation:

package com.java2novice.model;

import org.codehaus.jackson.annotate.JsonProperty;

public class Order {

	private String custmer;
	private String address;
	private String amount;
	public String getCustmer() {
		return custmer;
	public void setCustmer(String custmer) {
		this.custmer = custmer;
	public String getAddress() {
		return address;
	public void setAddress(String address) {
		this.address = address;
	public String getAmount() {
		return amount;
	public void setAmount(String amount) {
		this.amount = amount;

Remember that our restful web service API accepting json as an input, we should annotate our service method with @Consumes and specify MIME type as application/jon. Closely watch our service method input parameter, it is of type Order, before calling our service method, the json is mapped to Order object.

package com.java2novice.restful;


import com.java2novice.model.Order;
	public Response getUserById(Order inputOrder){
		System.out.println("Received order from :"+inputOrder.getCustmer());
		System.out.println("Order worth: "+inputOrder.getAmount());
		System.out.println("Customer address: "+inputOrder.getAddress());
		return Response.status(200).entity("Your order is in-progress").build();

Here is the json requst and response:

The console output:

[stdout] (http-- Received order from :Java2Novice
[stdout] (http-- Order worth: $2000
[stdout] (http-- Customer address: Bangalore
<< Previous Program | Next Program >>

Restful Web Services Examples

  1. Restful web services using RESTEasy hello world example.
  2. Restful web services using Jersey hello world example.
  3. JAX-RS @Path annotation example
  4. JAX-RS @Path annotation with regular expression match example
  5. JAX-RS @PathParam annotation example
  6. JAX-RS @QueryParam and @DefaultValue annotations example
  7. JAX-RS @MatrixParam annotation example
  8. How to read multiple values of a query paramter in JAX-RS restful web services?
  9. How to pass header parameters as method inputs in JAX-RS restful web services?
  10. How to read header parameters in JAX-RS restful web services?
  11. JAX-RS @FormParam annotation example
  12. How to upload file using Jersey restful web services?
  13. How to download file using java restful web services?
  14. XML based Restful web service with RESTEasy and JAXB.
  15. XML based Restful web service with Jersey and JAXB.
  16. Json based Restful web service with RESTEasy, Jettison and JAXB
  17. Json based Restful web service with RESTEasy and Jackson
  18. Json based Restful web service with Jersey and Jackson
  19. How to input json request with Jersey and Jackson?
  20. Java client for restful web service using package
  21. Java client for restful web service using Jersey API
  22. Java restful webservices with HTTP basic authentication.
Knowledge Centre
doPost Vs doGet methods
doGet() method is used to get information, while doPost() method is used for posting information. doGet() requests can't send large amount of information and is limited to 240-255 characters. However, doPost()requests passes all of its data, of unlimited length. A doGet() request is appended to the request URL in a query string and this allows the exchange is visible to the client, whereas a doPost() request passes directly over the socket connection as part of its HTTP request body and the exchange are invisible to the client.
Famous Quotations
It is easier to fight for one’s principles than to live up to them.
-- Alfred Adler

About Author

I'm Nataraja Gootooru, programmer by profession and passionate about technologies. All examples given here are as simple as possible to help beginners. The source code is compiled and tested in my dev environment.

If you come across any mistakes or bugs, please email me to [email protected].

Most Visited Pages

Other Interesting Sites

Reference: Java™ Platform Standard Ed. 7 - API Specification | Java™ Platform Standard Ed. 8 - API Specification | Java is registered trademark of Oracle.
Privacy Policy | Copyright © 2018 by Nataraja Gootooru. All Rights Reserved.