json - How can I tell RestTemplate to POST with UTF-8 encoding? -
i'm having problems posting json utf-8 encoding using resttemplate. default encoding json utf-8 media type shouldn't contain charset. have tried put charset in mediatype doesn't seem work anyway.
my code:
string datajson = "{\"food\": \"smörrebröd\"}"; httpheaders headers = new httpheaders(); mediatype mediatype = new mediatype("application", "json", standardcharsets.utf_8); headers.setcontenttype(mediatype); httpentity<string> entity = new httpentity<string>(datajson, headers); resttemplate resttemplate = new resttemplate(); responseentity<boolean> formentity = resttemplate.exchange(posturl, httpmethod.post, entity, boolean.class);
you need add stringhttpmessageconverter rest template's message converter charset utf-8.
resttemplate resttemplate = new resttemplate(); resttemplate.getmessageconverters() .add(0, new stringhttpmessageconverter(charset.forname("utf-8")));
Comments
Post a Comment