Parsing json into java objects in spring-mvc

Your parameter should either be a @RequestParam, or a @RequestBody, not both.

@RequestBody is for use with POST and PUT requests, where the body of the request is what you want to parse. @RequestParam is for named parameters, either on the URL or as a multipart form submission.

So you need to decide which one you need. Do you really want to have your JSON as a request parameter? This isn’t normally how AJAX works, it’s normally sent as the request body.

Try removing the @RequestParam and see if that works. If not, and you really are posting the JSON as a request parameter, then Spring won’t help you process that without additional plumbing (see Customizing WebDataBinder initialization).

Leave a Comment