title: Spring REST consumption results in HTTP Status 406 - Not Acceptable
body: <p>I get this error when i try to consume a REST API:</p>
  
  <pre><code>Exception in thread "main" org.springframework.web.client.HttpClientErrorException: 406 Not Acceptable
  </code></pre>
  
  <p>Here's the client code that gets executed:</p>
  
  <pre><code>public static void main(String[] args) {
     Car c = getCarById(4);
     System.out.println(c);
  }
  
  public static  @ResponseBody Car getCarById(int id){
      return new RestTemplate().getForObject("http://localhost:8080/rest/cars/{id}", Car.class, id);
  }
  </code></pre>
  
  <p>Here's the code of the Controller which maps the request:</p>
  
  <pre><code>@RequestMapping(value="/cars/{id}", method=RequestMethod.GET, headers = {"Accept=text/html,application/xhtml+xml,application/xml"}, produces="application/xml")
  public @ResponseBody Car getCarById(@PathVariable("id") int id){
      return carService.getCarById(id);
  }
  </code></pre>
  
  <p>Why is this error (406-Not Acceptable) happening although the mappers should take care of mapping to the correct types?</p>