Spring MVC @RequestBody and partial object/json binding Spring MVC @RequestBody and partial object/json binding json json

Spring MVC @RequestBody and partial object/json binding


You should be able to use a PATCH HTTP method

Its the preferred method that you would use when you need partial updates, like in your case when you want to update just a few fields of a resource

Spring MVC added a support for it in the version 3.2, so you can do something like

@RequestMapping(value="/patch", method=RequestMethod.PATCH, consumes=MediaType.APPLICATION_JSON_VALUE)public @ResponseBody String patch(@RequestBody Foo foo)    {    return foo.toString();}

and when sending the request, add only the properties you want to update to your PATCH request, the properties that are null or omited won't be updated

In the lack of better Spring MVC PATCH reference, I'm linking this SO thread as an interesting read Spring MVC PATCH method: partial updates