简体   繁体   English

如何将请求正文中的列表值发送到 Rest Api

[英]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.

相关问题 如何放心地在请求中发送复杂的正文? - How to send complex body in the request with rest assured? rest api - 如何在rest api调用中发送邮递员的身体参数 - rest api - how to send body parameters of postman in rest api call REST API如何接收请求正文数据? - How REST API receive request body data? 如何使用Rest-Assured请求POST API发送令牌和主体值? - How to request a POST API send token and body values using Rest-Assured? 如何从 java 中的列表中读取请求正文并使用 Rest Assured 命中 API? - How to read request body from a list in java and hit the API using Rest Assured? 如何将请求有效负载发送到Java中的REST API? - How to send Request payload to REST API in java? 如何发送包含多个对象的 Rest 模板请求正文 - How to I send a Rest Template Request Body with multiple objects in it "如何使用 REST Assured 在正文中将请求作为 Json 数组发送以进行 Post" - How to send Request as Json Array in body for Post using REST Assured 如何在restAssured的请求正文中发送带有列表的JSON post请求 - How to send a JSON post request with a list in request body in restAssured 如何通过 url 和 Z65E8800B5C6800AAD8800B5C6800AAD8800B5C6800AAD896F888B2A62AFCZ 的主体发送请求主体的 json 参数之一为@FCBmapping80AFD3511Z5 - How to send one of the json parameter of a request body through url and rest through body of postman for @Postmapping
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM