未找到响应类 ArrayList 的消息正文编写器 [英] No message body writer has been found for response class ArrayList
本文介绍了未找到响应类 ArrayList 的消息正文编写器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我试图返回 List 时,它抛出的响应类 ArrayList 没有找到任何消息正文编写器.
While I am trying to return List its throwing No message body writer has been found for response class ArrayList.
我的代码如下:
@POST
@Path("/{scope}/{application}/tables")
@Produces("application/xml")
public List<String> getTableNames(@PathParam("scope") String scope,
@PathParam("application") String application, Request request) {
// For example, I am returning a list of String
return new ArrayList<String>(4);
}
请帮帮我.提前致谢
推荐答案
要返回一个列表,最好将它包装到一个带有 @XmlRootElement
注释的容器中,并将您的列表作为一个字段提供给该容器,注释为@XmlElement
.
To return a list, best wrap it into a container annotated @XmlRootElement
and give that container your list as a field, annotated as @XmlElement
.
像这样:
@XmlRootElement
public class Container {
@XmlElement
public List yourlist;
}
这篇关于未找到响应类 ArrayList 的消息正文编写器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文