trap
trap

Reputation: 2640

ResponseEntity decode UTF-8

how can i decode UTF-8 in the ResponseEntity (especially when i get Umlauts). I also tried with SpringHttpMessageConverter, but this is not working.

RestTemplate restTemplate = new RestTemplate();
//this is not working only by POST
restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(Charset.forName("UTF-8")));

ResponseEntity<List<WebUser>> responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET,
                        requestEntity, new ParameterizedTypeReference<List<WebUser>>() {
                        });

//responseEntity.getBody().get(0).getFirstName() should be Müller but I get M&uuml;ler

Upvotes: 0

Views: 1051

Answers (1)

borowis
borowis

Reputation: 1235

should be Müller but I get M&uuml;ler

It's not an UTF-8 issue. &uuml; is an HTML entity (see here for the list of entities). You should unescape HTML entities in response to get UTF-8 strings that you want (see this answer on how to do that using Apache Commons).

Upvotes: 2

Related Questions