title: How can I tell RestTemplate to POST with UTF-8 encoding?
body: <p>I'm having problems posting JSON with UTF-8 encoding using RestTemplate. Default encoding for JSON is UTF-8 so the media type shouldn't even contain the charset. I have tried to put charset in the MediaType but it doesn't seem to work anyway.</p>
  
  <p>My code:</p>
  
  <pre><code>String dataJson = "{\"food\": \"smörrebröd\"}";
  HttpHeaders headers = new HttpHeaders();
  MediaType mediaType = new MediaType("application", "json", StandardCharsets.UTF_8);
  headers.setContentType(mediaType);
  
  HttpEntity&lt;String&gt; entity = new HttpEntity&lt;String&gt;(dataJson, headers);
  RestTemplate restTemplate = new RestTemplate();
  ResponseEntity&lt;Boolean&gt; formEntity = restTemplate.exchange(postUrl, HttpMethod.POST, entity, Boolean.class);
  </code></pre>