【问题标题】:Obtaining List or array of long as a parameter using jax-rs and jersey使用 jax-rs 和 jersey 获取 long 作为参数的列表或数组
【发布时间】:2015-10-07 14:42:38
【问题描述】:

我使用 JAX-RS 和 Jersey。我有这样的方法。它对我不起作用。

@POST
public Response addOrder(List<Long> ids) {
    ...
}

当我使用 Postman 发送请求时出现错误。

Can not deserialize instance of java.util.ArrayList out of START_OBJECT token 
at [Source: org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream@6befd3c2; line: 1, column: 1]

我的要求:

{
"ids": [1, 2, 3]
}

有没有办法让它工作?

【问题讨论】:

    标签: java json rest jax-rs


    【解决方案1】:

    你需要一个包含ids属性的类

    public class IdList {
      private List<Long> ids;
    
      // getter and setter
    }
    

    然后

    @POST
    public Response addOrder(IdList idList) {
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-23
      • 2011-10-26
      • 2015-03-02
      • 1970-01-01
      • 1970-01-01
      • 2011-07-25
      相关资源
      最近更新 更多