I am sending a list of json object and trying to deserialize it in my Spring controller. But all the time I am getting error of \'Bad request\' and results into a status co
As @shazin is saying, you've most likely posted a wrong method to your question, or if not, simply make a change that he suggested.
You'll need another fix, and that is renaming the usersList
property from UserWrapper
to users
so that it matches the JSON property being sent.
We these fixes, you should not have further problems, since your request is OK.
I think you need to change your @RequestBody
POJO to UserWrapper
@RequestMapping(value="/task/add", method=RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public void createTeamMember(@RequestBody UserWrapper userWrapper) {
// Code to create members
}
I will not suspect server side binding error yet because you are getting 415 - Unsupported Media Type error. You are setting correct media type on controller and hence server side is looking good.
At client side, Please make sure you are using jquery 1.5+ to make sure beforeSend() method is getting invoked.
Easier way to content type will be,
$.ajax({
url:api,
....
contentType: "application/json"
});
Please inspect network request from browser and make sure content type is set in header.
If you receive 400-Bad Request, then you can start looking deserializing issues.