grails-plugins/grails-rest-client-builder

Allow setting request encoding for RestBuilder

Opened this issue · 6 comments

Request currently send requests in default encoding ISO-8859-1 specified in StringHttpMessageConverter

To enable custom encoding, I had to use a hack:

RestBuilder rest = new RestBuilder()
rest.restTemplate.setMessageConverters([new StringHttpMessageConverter(Charset.forName("UTF-8"))])

RestBuilder needs a better and more obvious way to customize request encoding.

Thanks for posting the hack!

+1

provided workaround at the top of this conversation is replacing all message converters, so use carefully

In my case passing custom header with charset resolved my issue:
header('Content-Type', 'application/xml;charset=UTF-8')

For me only work like this:

def rest = new RestBuilder()
rest.restTemplate.setMessageConverters([new StringHttpMessageConverter(Charset.defaultCharset.forName("UTF-8"))])

thanks
@snowindy .. worked for me