泽西GenericEntity不工作 [英] Jersey GenericEntity Not Working

查看:153
本文介绍了泽西GenericEntity不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Jersey的GenericEntity将列表作为json返回。

I am using Jersey's GenericEntity to return a list as 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。

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

我需要在哪里向球衣提供更多信息。我不是在使用Maven。

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

中断的代码是

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


推荐答案

GenericEntity旨在嵌入在Response中方式:

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();
}

这篇关于泽西GenericEntity不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆