我使用Jersey 1.11创建了一个小的REST Web服务。当我调用返回JSON的URL时,非英文字符的字符编码出现问题。相应的XML URL(“test.xml”)在起始XML标记中使其成为utf-8。
我该如何使URL“test.json”返回UTF-8编码的响应?
以下是服务的代码:
@Stateless
@Path("/")
public class RestTest {
@EJB
private MyDao myDao;
@Path("test.xml/")
@GET
@Produces(MediaType.APPLICATION_XML )
public List<Profile> getProfiles() {
return myDao.getProfilesForWeb();
}
@Path("test.json/")
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Profile> getProfilesAsJson() {
return myDao.getProfilesForWeb();
}
}
这是服务使用的POJO:
package se.kc.mimee.profile.model;
@XmlRootElement
public class Profile {
public int id;
public String name;
public Profile(int id, String name) {
this.id = id;
this.name = name;
}
public Profile() {}
}