[英]How to send List value in Request Body to Rest Api
Hi i have written a Rest Service to accept List of Long values as input via RequestBody and the code for the same is given below:嗨,我已经编写了一个 Rest 服务来通过 RequestBody 接受长值列表作为输入,下面给出了相同的代码:
@DeleteMapping("/files")
public ResponseEntity<?> deletefiles(@RequestBody List<Long> ids) {
fileService.deleteSelectedfiles(ids);
return ResponseEntity.ok().build();
}
When i try to hit the above url from Postman i am getting the below error:当我尝试从 Postman 访问上述 url 时,出现以下错误:
"JSON parse error: Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: [![enter image description here][1]][1]Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token\n at [Source: (PushbackInputStream); line: 1, column: 1]"
In Postman i am sending data as Raw data in the following format在邮递员中,我以以下格式将数据作为原始数据发送
{"ids": [1 ,2]}
Can anyone help me on this谁可以帮我这个事
Your payload is expected to be a您的有效载荷预计为
[1 ,2]
Instead of代替
{"ids": [1 ,2]}
The first option is a json array and the second example is a json body.第一个选项是一个 json 数组,第二个示例是一个 json 主体。 You can use the first one with your
@RequestBody List<Long> ids
or the second one with @RequestBody YourData data
where您可以将第一个与
@RequestBody List<Long> ids
或者将第二个与@RequestBody YourData data
,其中
class YourData {
List<Long> ids
}
@RequestMapping(YOUR_REQUEST_MAPPINGS)
public void testArrayOfValues(@RequestParam List<String> values)
{
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.