Jersey GenericEntity Not Working

孤街醉人 提交于 2019-12-07 08:47:32

问题


I am using Jersey's GenericEntity to return a list as json.

However I'm getting the exception

A message body writer for Java type, class java.util.Arrays$ArrayList, and MIME media type, application/xml, was not found
16-May-2011 11:16:31 com.sun.jersey.spi.container.ContainerResponse traceException
SEVERE: Mapped exception to response: 500 (Internal Server Error)....

I know this means that Jersey is not setup to map to json properly.

Where do I need to give more information to jersey. I am not using Maven.

The code that breaks is

List<String> list = Arrays.asList("test", "as");
return new GenericEntity<List<String>>(list) {};

回答1:


A GenericEntity is meant to be embedded in a Response that way:

public Response get() {
    List<String> list = Arrays.asList("test", "as");
    return Response.ok(new GenericEntity<List<String>>(list) {}).build();
}


来源:https://stackoverflow.com/questions/6015970/jersey-genericentity-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!