Demonstration of updating and keeping fields using the JSON Merge Patch.
- Java 21
./mvnw clean spring-boot:run
Step 1: See the initial data.
curl -XGET "http://localhost:8080/users/1"
{"id":1,"username":"alice","familyName":"Liddell","givenName":"Alice","age":7}
Step 2: Update age and delete familyName by JSON Patch Merge request.
curl -XPATCH -H"Content-type:application/merge-patch+json" http://localhost:8080/users/1 -d '{"age":17, "familyName":null}'
{"id":1,"username":"alice","familyName":null,"givenName":"Alice","age":17}
Step 3: See the updated data.
curl -XGET "http://localhost:8080/users/1"
{"id":1,"username":"alice","familyName":null,"givenName":"Alice","age":17}