0

I am sending a PATCH request with null values in some properties of the entity and I see that the fields are updated in the database whereas according to spec they shouldn't (partial update). Trying to understand what's going on I see that the DomainObjectMerger is instantiated as a @Bean but its merge method never used (no references found and in debug mode breakpoint is never fired). Could someone explain how and when is the DomainObjectMerger used?

EDIT: I created a sample project with a failing test. The test tries to PATCH an entity passing null as a password and expects the password to not have been affected. But it fails because the password is now null in the database

https://github.com/otinanism/demo-rest-data

1 Answer 1

4

The code works as expected. Your PATCH payload looks like this:

{"id":"bc421109-edaf-4d4f-8d4c-71b62aa4d99f","username":"alex","password":null}

That's telling the server to wipe out the value for the password field. If you want to leave the password field untouched, make sure it's not even contained in the request payload, e.g. by configuring the ObjectMapper to not render null values.

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

2 Comments

This works indeed (but is it documented anywhere?). So, I suppose that DomainObjectMerger is unrelated to this? I got confused because of this old issuse: jira.spring.io/browse/DATAREST-130 Thanksa lot for the feedback!
The behaviour is basically what's defined in RFC7386.

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.