Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add UTF-8 encoding to ResponseEntity

Tags:

spring

I have a responseEntity like this one:

HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
requestHeaders.setContentType(MediaType.valueOf("text/plain;charset=UTF-8"));

HttpEntity requestEntity = new HttpEntity(jsonQuery, requestHeaders);
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);

//Not in UTF-8!!
logger.debug("result: " + responseEntity.getBody());

But it's not encoded in UTF-8 and produces characters like this: Soci굩 . Is it possible to make it in UTF-8 or add the encoding somehow in restTemplate?

like image 497
dimzak Avatar asked Sep 16 '14 15:09

dimzak


1 Answers

responseHeaders.add("Content-Type", "text/html; charset=utf-8");
like image 132
Ahmad R. Nazemi Avatar answered Sep 20 '22 18:09

Ahmad R. Nazemi