java - REST - 如何使用 Jersey 传递一个 long in 参数数组?

标签 java rest jax-ws jersey

我正在尝试使用 Jersey 传递一个 long 数组:

在客户端我尝试过类似的东西:

@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);

关于java - REST - 如何使用 Jersey 传递一个 long in 参数数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4878043/

相关文章:

java - 在java中处理/读取.BAI2文件

c# - Restful Versioning - 如何在版本控制中进行版本控制以及如何部署?

java - 如何使用 JAXB 编码注释为 @XmlAttachmentRef 的 DataHandler?

java - 全屏时视口(viewport)似乎稍微偏离屏幕

Java : How to accommodate special characters in the filename while uploading and downloading the file?

java - RESTFUL API 中的几个登录

java - 具有不同对象类型的重复代码

java - 开发使用安全 METRO 2.1 Web 服务的 .NET 客户端

web-services - 每次网络服务调用时自动传递一个 cookie

java - 在java中解析1GB xml数据的最佳解析器