title: 415 Unsupported Media Type (org.springframework.web.client.HttpClientErrorException)
body: <p>I am new to WebServices. I am working on an application where I am using AnhularJs1.x at client side which sends data to Spring Rest Controller.</p>
  
  <p>The architecture of the application is micro-services based. I am able to receive the data from angular to Front end Rest Controller which are in the same war.</p>
  
  <p>From this controller I am calling a service which internally calls another micro-service which interacts with database.</p>
  
  <p>When I am sending the data received in my front end controller to another micro-service I get <strong>415 Unsupported Media Type (org.springframework.web.client.HttpClientErrorException)</strong></p>
  
  <p>Below is my front end controller which is in the same war as angularJS </p>
  
  <pre><code>@RequestMapping(value = "/servicearticles",  method = RequestMethod.POST,        produces = MediaType.APPLICATION_JSON_VALUE)
  public ResponseEntity&lt;ServiceArticle&gt; saveData(@RequestBody      List&lt;ServiceArticle&gt; serviceArticleList){
      System.out.println("In savedata");
      System.out.println(serviceArticleList.toString());
  
  
      try {
          if(null != serviceArticleList &amp;&amp; serviceArticleList.size() &gt;0){
              serviceArticleAdminService.insertData(serviceArticleList);
          }else{
              logger.error("File is empty. No data to save");
          }
  </code></pre>
  
  <p>I am able to get data in this contoller :
  [ServiceArticle [articleId=17070, productCode=1000, productName=Business Parcel zone , zone=1], ServiceArticle [articleId=17071, productCode=1001, productName=Business Parcel zone , zone=4], ServiceArticle [articleId=17070, productCode=1012, productName=Business Parcel zone , zone=5], ServiceArticle [articleId=17070, productCode=1000, productName=Business Parcel zone , zone=1], ServiceArticle [articleId=17070, productCode=1000, productName=Business Parcel zone , zone=2]]</p>
  
  <p>When I call the different microservice from my serviceImpl class I get the unsupported media type error</p>
  
  <p>Code for serviceImpl class</p>
  
  <pre><code>private final String URI = "http://localhost:8082/admin/import/servicearticles";
  
  @Override
  public void insertData(List&lt;ServiceArticle&gt; serviceArticles) {
      logger.error("Inside insertData() in service");
  
      RestTemplate restTemplate = new RestTemplate();
  
      try {
              restTemplate.postForObject(URI, serviceArticles, ServiceArticle.class);
      } catch (ResourceAccessException e) {
          logger.error("ServiceArticleAdmin Service Unavailable.");
  </code></pre>
  
  <p>Below is the code for the controller in different micro-servie which maps to this call </p>
  
  <pre><code>@RequestMapping(value = "/import/servicearticles", method =    RequestMethod.POST, consumes= MediaType.APPLICATION_JSON_VALUE , produces = MediaType.APPLICATION_JSON_VALUE)
   public ResponseEntity&lt;ServiceArticle&gt; addAll(@RequestBody List&lt;ServiceArticle&gt; serviceArticles) {
  
      List&lt;ServiceArticle&gt; serviceArticlesAdded = serviceArticleAdminService.addAll(serviceArticles);
  
      return new ResponseEntity(serviceArticlesAdded, HttpStatus.OK);
  }
  </code></pre>
  
  <p>I have added the below dependencies in my pom.xml</p>
  
  <pre><code>   &lt;dependency&gt;
          &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
          &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
          &lt;version&gt;2.8.6&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;com.fasterxml.jackson.dataformat&lt;/groupId&gt;
          &lt;artifactId&gt;jackson-dataformat-xml&lt;/artifactId&gt;
          &lt;version&gt;2.8.6&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>I have the following bean definition in my servlet-context.xml</p>
  
  <pre><code>&lt;bean
      class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"&gt;
      &lt;property name="messageConverters"&gt;
          &lt;list&gt;
              &lt;ref bean="jsonMessageConverter" /&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;!-- To convert JSON to Object and vice versa --&gt;
  &lt;bean id="jsonMessageConverter"
      class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Please help me figure out where am I making a mistake.
  Is there any way I can set response type as application/json when I am invoking
  restTemplate.postForObject method</p>
  
  <p>I verified using a REST client plugin it works there but not through my Java code. Please help.</p>