gravity9-tech / json-patch-path

An RFC 6902 (JSON Patch) and reverse, plus RFC 7386 (JSON Merge Patch), implementation in Java using Jackson (2.x)
Other
11 stars 1 forks source link

Add operation overwrite previous value #60

Closed GuanqunYang193 closed 6 months ago

GuanqunYang193 commented 6 months ago

In current implement, it seems if we add value to a pre-existed path, the old value will be overwrited. In order to identify the semantics of "add" and "update", should we check if the path already existed and throw exception.

meehaws commented 6 months ago

Indeed. That is the behaviour correct as described in Json Patch RFC 6902:

4.1.

add

The "add" operation performs one of the following functions, depending upon what the target location references:

o If the target location specifies an object member that does exist, that member's value is replaced.

If you want to check if the path exists, you can use test operation and combine it with add: 4.6 test operation

GuanqunYang193 commented 6 months ago

Indeed. That is the behaviour correct as described in Json Patch RFC 6902:

4.1. add The "add" operation performs one of the following functions, depending upon what the target location references: o If the target location specifies an object member that does exist, that member's value is replaced.

If you want to check if the path exists, you can use test operation and combine it with add: 4.6 test operation

Brilliant! Thanks!