title: Java Spring POST API json input
body: <p>Developing a java spring based API for the first time. These APIs will be POST and would take JSON as input. I must not be connecting all of the dots because there is an error message when I invoke the api call from my rest client. </p>
  
  <p>pom.xml</p>
  
  <pre><code>      &lt;dependency&gt;
          &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
          &lt;artifactId&gt;jackson-core&lt;/artifactId&gt;
          &lt;version&gt;2.5.3&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>Object to serialize from json</p>
  
  <pre><code>public class PostCountry {
      private String country;
  
  
      public void setCountry(String country){
          this.country=country;
      }
      public String getCountry() {
          return country;
      }
  
  }
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>@RequestMapping(value = "/getCountries", method = RequestMethod.POST, consumes = "application/json")
      public @ResponseBody String getCountries(PostCountry country) {
          System.out.println(country.getCountry());
          MapDAOImpl mapDAOImpl = (MapDAOImpl) appContext.getBean("mapDAOImpl");
          System.out.println(mapDAOImpl.getCountries(country.getCountry()));
          return "";
  
      }
  </code></pre>
  
  <p>Error message thrown in rest client</p>
  
  <pre><code>&lt;u&gt;The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.&lt;/u&gt;
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/P6LOr.png" alt="Rest call"></p>
  
  <p>error</p>
  
  <pre><code>System.out.println(country.getCountry()); is null
  </code></pre>