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:
@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:
"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. You can use the first one with your @RequestBody List<Long> ids
or the second one with @RequestBody YourData data
where
class YourData {
List<Long> ids
}
@RequestMapping(YOUR_REQUEST_MAPPINGS)
public void testArrayOfValues(@RequestParam List<String> values)
{
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.