2011-05-16 69 views
4

我正在使用Jersey的GenericEntity將列表返回爲json。Jersey GenericEntity不工作

不過,我發現了異常

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).... 

我知道這意味着澤西沒有設置映射到正確的JSON。

我需要向球衣提供更多信息。我沒有使用Maven。

,打破該代碼是

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

回答

2

甲GenericEntity意欲被嵌入在響應這種方式:

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