I am sending this from the frontend via POST ajax:
It consists of JSON array and object.
EDIT: I have set :
contentType: 'application/json'
The exact JSON is sent as follows:
{
"alertKeeperDTOs": [
{
"isSelected": true,
"rn": 0,
"keeperId": "B116453993D52735E0530A10CA0A9D27",
"keeperName": "myName"
},
{
"isSelected": false,
"rn": 1,
"keeperId": "65EE22D4A55C4437A4F5552CBFD8D6D0",
"keeperName": "test",
}
],
"deviceId": 4
}
I am trying to get this from the Controller: (EDITED)
public @ResponseBody String updateDeviceToKeeperList(@RequestBody List<AlertKeeperDTO> alertKeeperDTOs,
@RequestBody Long deviceId, HttpServletRequest request){
....
}
But I am getting an error (HTTP 400):
Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of
java.util.ArrayListout of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance ofjava.util.ArrayListout of START_OBJECT token at [Source: (PushbackInputStream); line: 1, column: 1]]
How can I code my controller backend? Please help. Thanks.
Content-Typeheader of your request, you said you're sending JSON body, but it looks like theContent-Typeisapplication/x-www-form-urlencodedinstead ofapplication/json. Also, use@RequestBodyannotation instead of@RequestParamif you want to map request body toalertKeeperDTOs