Java 如何返回arraylist作为对restful cxf webservice调用的响应

Java 如何返回arraylist作为对restful cxf webservice调用的响应,java,web-services,rest,arraylist,cxf,Java,Web Services,Rest,Arraylist,Cxf,我正在尝试使用restful cxf webservice调用从MongoDB检索文档列表。但我面对的是 在类ArrayList中找不到响应的消息正文编写器 我跟着。在这里,他们返回employee对象作为cxfrestservicepimpl类中的响应。所以他们使用了@xmlement(name='employee') 但现在,我试图从MongoDB返回文档列表,作为CxfRestServiceImpl类中的响应。为了克服此错误,我需要做哪些更改?如果我理解您的意思是正确的,那么代码中就出现了

我正在尝试使用restful cxf webservice调用从MongoDB检索文档列表。但我面对的是

在类ArrayList中找不到响应的消息正文编写器

我跟着。在这里,他们返回employee对象作为
cxfrestservicepimpl
类中的响应。所以他们使用了
@xmlement(name='employee')


但现在,我试图从MongoDB返回文档列表,作为
CxfRestServiceImpl
类中的响应。为了克服此错误,我需要做哪些更改?

如果我理解您的意思是正确的,那么代码中就出现了此异常。相比之下,你最好在其他课程中总结你的列表答案

@XmlRootElement(name="DocumentList")
public class DocumentList {
    @XmlElement
    public List<Document> documentList;
}
@XmlRootElement(name=“DocumentList”)
公共类文档列表{
@XmlElement
公共清单文件清单;
}

如果我理解你的意思是正确的,那么你的代码中就有这个异常。相比之下,你最好在其他课程中总结你的列表答案

@XmlRootElement(name="DocumentList")
public class DocumentList {
    @XmlElement
    public List<Document> documentList;
}
@XmlRootElement(name=“DocumentList”)
公共类文档列表{
@XmlElement
公共清单文件清单;
}

您可以返回服务中的对象列表。JAXB将从ArrayList进行转换

@GET
@Path("/employees")
public List<Employee> getEmployees()

您可以返回服务中的对象列表。JAXB将从ArrayList进行转换

@GET
@Path("/employees")
public List<Employee> getEmployees()
您可以像这样“包装”到数组中

return Response.status(Response.Status.OK).entity(yourList.toArray(new YourObject[yourList.size()])).build();
如果列表是
列表
数组列表

,则可以像这样“包装”到数组中

return Response.status(Response.Status.OK).entity(yourList.toArray(new YourObject[yourList.size()])).build();

如果您的列表是
列表
数组列表

非常感谢