Multiple @RequestBody values in one controller method

spring-mvc

Solution

You cannot use two `@RequestBody` as it can bind to a single object only (the body can be consumed only once). As Luke explained the easiest would be to create one object that will capture all the relevent data, and than create the objects you have in the arguments.

On the other hand, if you're insisting on your approach, you can create a custom `ArgumentResolver` as explained here

Problem

I'm receiving error 400 when I send PATCH request to my endpoint that looks like this ``` @RequestMapping(value = "...", method = RequestMethod.PATCH, consumes = "application/json", produces = "application/json") @ResponseBody public User updateUserPartial(@PathVariable("userId") String userId, @RequestBody Map<String, Object> userMap, @RequestBody User user, HttpServletResponse response) { ... } ``` so basically both userMap and user should contain same data in different structure. If I omit one @RequestBody value, this seems to work correctly. Is it somehow possible to have both @RequestBody values?

Original source

Related problems