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

Support for test operation with null value against empty path #37

Closed piotr-bugara-gravity9 closed 1 year ago

piotr-bugara-gravity9 commented 1 year ago

Issue copied from: https://github.com/java-json-tools/json-patch/issues/133

When performing a test operation, we should be able to test that a path inside a document is null. Instead, the library always throws an empty path exception without even checking if the value to test against is null.

Example:

Given the document:

{ "field1": {"id": 123}, "field2": {"id": 321} }

and the patch:

[ {"op": "test", "path": "field3", "value": null}, {"op": "add", "path": "field3", "value": {"id": 456}} ]

Expected: Successful patch Actual: Throws empty path exception

If operations like this were supported in the library it would allow users to perform "put if absent" operations inside json documents, since all the patch operations are executed atomically, which could be useful for several applications.

piotr-bugara-gravity9 commented 1 year ago

Test operation is not needed as we support JsonPath. We can do an add operation with filter predicate to add value to object that does not have path or it's value is equal to null.