我试图通过泽西传递一个长阵:
在客户端,我尝试过这样的事情:
@GET
@Consume("text/plain")
@Produces("application/xml)
Response getAllAgentsById(@params("listOfId") List<Long> listOfId);
有没有办法实现这样的事情?
提前致谢!
最佳答案 如果您想坚持使用“application / xml”格式并避免使用JSON格式,则应将此数据包装到JAXB注释对象中,以便Jersey可以使用内置的
MessageBodyWriter/
MessageBodyReader.
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public ListOfIds{
private List<Long> ids;
public ListOfIds() {}
public ListOfIds(List<Long> ids) {
this.ids= ids;
}
public List<Long> getIds() {
return ids;
}
}
在客户端(使用Jersey客户端)
// get your list of Long
List<Long> list = computeListOfIds();
// wrap it in your object
ListOfIds idList = new ListOfIds(list);
Builder builder = webResource.path("/agentsIds/").type("application/xml").accept("application/xml");
ClientResponse response = builder.post(ClientResponse.class, idList);