2

I have a large object which can be updated in a few steps. I'am facing a partial binding problem. My service consumes json and I can not use @InitBinder along with @RequestBody. Cutting this object to a few small ones is not good a solution, because there is a lot of cross-field validations between steps.

Do you have any ideas how to solve this? I'am looking for a clean solution like: registering a specific object mapper for given @RequestMapping or something like that. Thanks for help.

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

1 Comment

It's more like a security issue. I would like to add 'disallowedFields' on the specific step, so the caller can not bind data from the other step.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.