我正在使用 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。
我需要在哪里向 Jersey 提供更多信息。我没有使用 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();
}
关于java - 泽西通用实体不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6015970/