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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With