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 as XML using just:
@Produces("application/xml")
Everything is ok.
What do I need to set to produce the right type?
The given content type may include a character encoding specification, for example, text/html;charset=UTF-8. The response's character encoding is only set from the given content type if this method is called before getWriter is called. This method may be called repeatedly to change content type and character encoding.
JAX-RS is a Java programming language API designed to make it easy to develop applications that use the REST architecture. The JAX-RS API uses Java programming language annotations to simplify the development of RESTful web services.
Why use JAX-RS / Jersey? Because it makes the development of RESTful services easier. JAX-RS is a standard that makes it easy to create a RESTful service that can be deployed to any Java application server: GlassFish, WebLogic, WebSphere, JBoss, etc.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With