I'm working on developing some REST web services for an existing Java application. I'm using Resteasy JAX-RS by JBoss (as the existing application runs on a JBoss serer).
The web serivce below is supposed to return a User object based on the id number.
@GET
@Path("/getUser")
@Produces(MediaType.APPLICATION_XML)
public User getUser(@QueryParam("userId") int userId) {
return User.load(userId);
}
The User contains at least an ID and a name.
public class User {
private int id;
private String name;
}
When JAX-RS produces the XML document, it fails to handle special characters like æ ø å, that may occur in a name.
The output XML claims to be encoded in UTF-8, but it still fails to show æ ø å.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<user>
<id>18549</id>
<name>Københavner 1</name>
</user>
Every object I try to convert to XML this way fails to encode 'æøå' properly.
Any suggestions? Searching the web didn't help much either.
UPDATE: When I receive the XML on the client side, I first handle it as a String before using JAXB to unmarshal it into an object. I forgot to set the encoding of the String to UTF-8. So basically doing this before unmarshalling:
new String(((String) response).getBytes(), "UTF-8");