I'm using JAX-RS to create a web (rest) service that returns results in JSON format.
Everything is OK, except the encoding.
For example, I get:
..., parameter:"Dep\u00f3sitos" ,...
Instead of:
..., parameter:"Depósitos" ,...
I've tried using:
@Produces("application/json; charset=UTF-8")
but the problem remains. If I return it a开发者_如何转开发s XML using just:
@Produces("application/xml")
Everything is ok.
What do I need to set to produce the right type?
All you need is this:
String back = "Depósitos";
return new String(back.getBytes(), "UTF8");
I ended up using GSON instead of IBM's JSON4J which proved to be much better at handling custom Java class serialization.
Take a look at Bryant Luk's answer to the question "How to set the charset with JAX-RS?" and see if it does the trick.
精彩评论