title: Invalid mime type in spring rest template?
body: <p>I am just trying to make a simple REST request like below</p>
  
  <pre><code>String url = "some url";
  MultiValueMap&lt;String, String&gt; headers = new LinkedMultiValueMap&lt;&gt;();
  headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
  headers.add(HttpHeaders.AUTHORIZATION, "some authorization");
  RestTemplate restTemplate = new RestTemplate();
  restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
  Body body = new Body();
  body.setRemarks("test");
  org.springframework.http.HttpEntity request = new org.springframework.http.HttpEntity(body, headers);
  try {
      ResponseEntity&lt;String&gt; response = restTemplate.exchange(url, HttpMethod.PUT, request, String.class);
      System.out.println("Status Response: "+ response.getStatusCode() +". Body: "+ response.getBody());
  } catch (HttpClientErrorException | HttpServerErrorException e) {
      e.printStackTrace();
  } catch (Exception e) {
      e.printStackTrace();
  }
  </code></pre>
  
  <p>Problem is every time I do this in Java the result is unpredictable I am usually getting this error consistently.</p>
  
  <pre><code>org.springframework.http.InvalidMediaTypeException: Invalid mime type "text/plain, application/json, application/json, application/*+json, application/*+json, */*; charset=UTF-8": Invalid token character ',' in token "plain, application/json, application/json, application/*+json, application/*+json, */*"
  at org.springframework.http.MediaType.parseMediaType(MediaType.java:452)
  at org.springframework.http.HttpHeaders.getContentType(HttpHeaders.java:745)
  at org.springframework.web.client.DefaultResponseErrorHandler.getCharset(DefaultResponseErrorHandler.java:115)
  at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:63)
  at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:700)
  at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:653)
  at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:613)
  at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:531)
  </code></pre>
  
  <p>However when I try the same request through postman it works. I am missing something very simple and I do not know what.</p>
  
  <p>I checked the response from Postman and the headers, and they seem to hold good like <code>Content-Type →application/json; charset=UTF-8</code> and the response is also well formed.</p>
  
  <p>I am also not able to make out which part whether the request or the response is on which Rest Template is having a problem.</p>