The way I read the the paragraph you sent, I would say.. no you are not able to do this. My understanding is that RFC 7396 is intended as a very simple no-fuss patch format.
If you want something with more features, consider using RFC 6902 instead.
Answer from Evert on Stack OverflowThe way I read the the paragraph you sent, I would say.. no you are not able to do this. My understanding is that RFC 7396 is intended as a very simple no-fuss patch format.
If you want something with more features, consider using RFC 6902 instead.
Summary
You can achieve what you want with RFC 7396.
The spec is a bit vague.
But their example shows exactly what you want.
RFC 7396 Example
Given the following example JSON document:
{
"title": "Goodbye!",
"author" : {
"givenName" : "John",
"familyName" : "Doe"
},
"tags":[ "example", "sample" ],
"content": "This will be unchanged"
}
PATCH /my/resource HTTP/1.1
Host: example.org
Content-Type: application/merge-patch+json
{
"title": "Hello!",
"phoneNumber": "+01-123-456-7890",
"author": {
"familyName": null
},
"tags": [ "example" ]
}
The resulting JSON document would be:
{
"title": "Hello!",
"author" : {
"givenName" : "John"
},
"tags": [ "example" ],
"content": "This will be unchanged",
"phoneNumber": "+01-123-456-7890"
}
Conclusions
As you can see, the nested object author has been updated by deleting attribute familyName, but it retained attribute givenName even though that was not included in the patch document.
For me that clearly shows that you do not need to provide nested attributes or objects that you do not want to change and they should be retained.
Consequently, if you want to delete them, you need to include them with null value.
Note that the authors of spec managed to get most of the possible changes into one example (well done):
- change value of existing attribute
title - change object
author - delete nested attribute
familyName - keep unchanged nested attribute
givenName - change array value of
tags - keep unchanged attribute
content - add attribute
phoneNumber