Thursday, August 20, 2020

RestTemplate to POST with UTF-8 encoding

Sometime we see extra character in rest response like Â, â. To overcome this issue We need to add StringHttpMessageConverter to rest template's message converter with charset UTF-8. Like below


RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters()
        .add(0, new StringHttpMessageConverter(StandardCharsets.UTF_8));


Refer : UTF encoding from rest response