gpt4 book ai didi

java - 使用 jax-rs 和 jersey 获取长整型列表或数组作为参数

转载 作者:太空宇宙 更新时间:2023-11-04 13:21:48 25 4
gpt4 key购买 nike

我使用 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]
}

有什么办法可以让它发挥作用吗?

最佳答案

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

public class IdList {
private List<Long> ids;

// getter and setter
}

然后

@POST
public Response addOrder(IdList idList) {
}

关于java - 使用 jax-rs 和 jersey 获取长整型列表或数组作为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32995295/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com