我使用Jersey的GenericEntity将列表作为json返回.
但是我得到了例外
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)....
我知道这意味着Jersey不能正确映射到json.
我在哪里需要向球衣提供更多信息.我不是在使用Maven.
破解的代码是
List<String> list = Arrays.asList("test", "as");
return new GenericEntity<List<String>>(list) {};
最佳答案 GenericEntity意味着以这样的方式嵌入到Response中:
public Response get() {
List<String> list = Arrays.asList("test", "as");
return Response.ok(new GenericEntity<List<String>>(list) {}).build();
}