title: @PostMapping not working. HTTP 415 Unsupported MediaType Error
body: <p>I have created a @RestController and mapped a @PostMapping request.</p>
  
  <p>I am passing Content Type as "application/json" to the controller where I am reading the JSON with @RequestBody annotation mapping it to my Model class object.</p>
  
  <blockquote>
    <p>@RestController:</p>
  </blockquote>
  
  <pre><code>@PostMapping("/saveUser")
  public UserDetails save(@RequestBody UserDetails user) {
      System.out.println("from json input : "+user.idVal+" : "+user.getName());
      service.save(user);
      JSONObject jsn = new JSONObject();
      jsn.put("Result", user.getName());
      return user;
  }
  </code></pre>
  
  <blockquote>
    <p>HTTP Request</p>
  </blockquote>
  
  <pre><code>{
  "idVal":"asdadasd",
  "name":"TestUser"
  }
  </code></pre>
  
  <blockquote>
    <p>Model Class</p>
  </blockquote>
  
  <pre><code>import javax.persistence.Entity;
  javax.persistence.Id;
  
  @Entity
  public class UserDetails {
  
      @Id
      public String idVal;
      public String name;
  
      public String getId() {
          return idVal;
      }
      public void setId(String id) {
          this.idVal = id;
      }
  
      public String getName() {
          return name;
      }
      public void setName(String name) {
          this.name = name;
      }
  }
  </code></pre>
  
  <p>I am using Postman as the REST Client.</p>
  
  <p>Following is the error I am getting:</p>
  
  <pre><code>HTTP Status 415 â€“ Unsupported Media Type
  Type Status Report
  
  Description The origin server is refusing to service the request because the payload is in a format not supported by this method on the target resource.
  
  Apache Tomcat/8.5.31
  </code></pre>
  
  <p>I have tried as following:</p>
  
  <pre><code>@PostMapping(value="/saveUser", consumes=MediaType.APPLICATION_JSON_VALUE, produces=MediaType.APPLICATION_JSON_VALUE)
  public UserDetails save(@RequestBody UserDetails user) {
      System.out.println("from json input : "+user.idVal+" : "+user.getName());
      service.save(user);
      JSONObject jsn = new JSONObject();
      jsn.put("Result", user.getName());
      return user;
  }
  </code></pre>
  
  <blockquote>
    <p>Edit:</p>
  </blockquote>
  
  <p>Below is the complete Postman Request:</p>
  
  <pre><code> POST /Zcrud/saveUser HTTP/1.1
  Host: localhost:8080
  Content-Type: application/json
  Cache-Control: no-cache
  Postman-Token: fa4cfc76-d60c-f8dd-53b9-fd8b0b27ef7d
  
  {
      "idVal":"asdadasd",
      "name":"TestUser"
  }
  </code></pre>
  
  <p>Response:</p>
  
  <pre><code>&lt;!doctype html&gt;&lt;html lang="en"&gt;&lt;head&gt;&lt;title&gt;HTTP Status 415 – Unsupported Media Type&lt;/title&gt;&lt;style type="text/css"&gt;h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}&lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;HTTP Status 415 – Unsupported Media Type&lt;/h1&gt;&lt;hr class="line" /&gt;&lt;p&gt;&lt;b&gt;Type&lt;/b&gt; Status Report&lt;/p&gt;&lt;p&gt;&lt;b&gt;Description&lt;/b&gt; The origin server is refusing to service the request because the payload is in a format not supported by this method on the target resource.&lt;/p&gt;&lt;hr class="line" /&gt;&lt;h3&gt;Apache Tomcat/8.5.31&lt;/h3&gt;&lt;/body&gt;&lt;/html&gt;
  </code></pre>