没有为响应类ArrayList找到消息正文编写器

asw*_*yak 12 java web-services cxfrs

当我试图返回List时,它已经找到了没有消息体编写器的响应类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);
}
Run Code Online (Sandbox Code Playgroud)

请帮我.提前致谢

Urs*_*pke 19

要返回一个列表,最好将其包装到一个带注释的容器中@XmlRootElement,并将该列表作为一个字段给予该容器,注释为@XmlElement.

像这样:

@XmlRootElement
public class Container {
    @XmlElement
    public List yourlist;
}
Run Code Online (Sandbox Code Playgroud)

  • 并确保`Container`有一个默认的no-args构造函数:) (2认同)