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

Ignore specific fields while calculating JSON diff #30

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/80

When I find the difference between two JsonNodes, I shall be able to ignore specific fields.

Example:

Foo.java has id and name fields and I have two different objects of this class say foo1 and foo2.

When I compare the diff using JsonDiff class, I shall be able to ignore id comparison and be able to find diff for name field only.

JsonNode oldJsonNode = objectMapper.readTree(objectMapper.writeValueAsString(foo1));
JsonNode newJsonNode = objectMapper.readTree(objectMapper.writeValueAsString(foo2));
JsonNode jsonDiff = JsonDiff.asJson(oldJsonNode, newJsonNode);

I want to exclude id field in jsonDiff object.

piotr-bugara-gravity9 commented 1 year ago

done