title: How to create a POST request in REST to accept a JSON input?
body: <p>I am trying to learn RESTful web services. And am creating a simple set of web services. Got stuck when I started working on POST.</p>
  
  <p>I want to pass JSON input to a POST method. This is what I did in the code:</p>
  
  <pre><code>@RequestMapping(value = "/create", method = RequestMethod.POST, consumes="application/x-www-form-urlencoded", produces="text/plain")
  @ResponseStatus(HttpStatus.CREATED)
  public @ResponseBody String createChangeRequest(MyCls mycls) {
      return "YAHOOOO!!"; 
  }
  </code></pre>
  
  <p>I included Jackson in my POM.xml.</p>
  
  <pre><code> &lt;dependency&gt;
      &lt;groupId&gt;org.codehaus.jackson&lt;/groupId&gt;
      &lt;artifactId&gt;jackson-mapper-lgpl&lt;/artifactId&gt;
      &lt;version&gt;1.9.13&lt;/version&gt;
  &lt;/dependency&gt;   
  </code></pre>
  
  <p>MyCls is a simple class with a few getters and setters.</p>
  
  <p>I am calling the above POST service from chrome's simple REST client.</p>
  
  <pre><code>URL: http://localhost:8080/MYWS/cls/create
  Data: {&lt;valid-json which corresponds to each variable in the MyCls pojo}
  </code></pre>
  
  <p>I see the below response:</p>
  
  <pre><code>415 Unsupported Media Type
  The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.
  </code></pre>
  
  <p>I tried adding header as "application/json" in the POST request in the REST client - but that did not help.</p>
  
  <p>Can someone let me know what I am missing here? How can I automatically map my input JSON to the MyCls pojo? Am I missing any configuration here?</p>
  
  <p>Edit:
  MyCls.java</p>
  
  <pre><code>public class MyCls{
     private String name;
     private String email;
     private String address;
         public String getName() {
      return name;
     }
     public void setName(String name) {
      name= name;
     }
         ---similar getter and setter for email, address--
  }
  </code></pre>
  
  <p>json from chrome Simple REST Client:</p>
  
  <pre><code>{"name":"abc", "email":"de@test","address":"my address"}
  </code></pre>
  
  <p>Edit:
  Changed my controller method to the following, but still see the same error:</p>
  
  <pre><code>@RequestMapping(value = "/create", method = RequestMethod.POST, consumes="application/json", produces="text/plain")
  @ResponseStatus(HttpStatus.CREATED)
   public @ResponseBody String createChangeRequest(@RequestBody MyCls mycls) {
    return "YAHOOOO!!"; 
   }
  </code></pre>