title: Why RestTemplate GET response is in JSON when should be in XML?
body: <p>I struggled with an extrange spring behavior using RestTemplate (org.springframework.web.client.RestTemplate) without success.</p>
  
  <p>I use in my hole application below code and always receive an XML response, which I parse and evaluate its result.</p>
  
  <pre><code>String apiResponse = getRestTemplate().postForObject(url, body, String.class);
  </code></pre>
  
  <p>But can't figure out why a server response is in JSON format after executing:</p>
  
  <pre><code>String apiResponse = getRestTemplate().getForObject(url, String.class);
  </code></pre>
  
  <p>I've debugged at low level RestTemplate and the content type is XML, but have no idea why the result is in JSON.</p>
  
  <p>When I access from a browser the response is also in XML, but in apiResponse I got JSON. </p>
  
  <p>I tried many options after reading Spring documentation
  <a href="http://docs.spring.io/spring/docs/3.0.x/api/org/springframework/web/client/RestTemplate.html" rel="noreferrer">http://docs.spring.io/spring/docs/3.0.x/api/org/springframework/web/client/RestTemplate.html</a></p>
  
  <p>Also tried to modify explicitly the headers but still can't figure it out.</p>
  
  <p>I debugged RestTemplate class and noticed that this method is always setting application/json:</p>
  
  <pre><code>public void doWithRequest(ClientHttpRequest request) throws IOException {
              if (responseType != null) {
                  List&lt;MediaType&gt; allSupportedMediaTypes = new ArrayList&lt;MediaType&gt;();
                  for (HttpMessageConverter&lt;?&gt; messageConverter : getMessageConverters()) {
                      if (messageConverter.canRead(responseType, null)) {
                          List&lt;MediaType&gt; supportedMediaTypes = messageConverter.getSupportedMediaTypes();
                          for (MediaType supportedMediaType : supportedMediaTypes) {
                              if (supportedMediaType.getCharSet() != null) {
                                  supportedMediaType =
                                          new MediaType(supportedMediaType.getType(), supportedMediaType.getSubtype());
                              }
                              allSupportedMediaTypes.add(supportedMediaType);
                          }
                      }
                  }
                  if (!allSupportedMediaTypes.isEmpty()) {
                      MediaType.sortBySpecificity(allSupportedMediaTypes);
                      if (logger.isDebugEnabled()) {
                          logger.debug("Setting request Accept header to " + allSupportedMediaTypes);
                      }
                      request.getHeaders().setAccept(allSupportedMediaTypes);
                  }
              }
          }
  </code></pre>
  
  <p>Could you give an idea?</p>