flipkart-incubator / zjsonpatch

This is an implementation of RFC 6902 JSON Patch written in Java
Apache License 2.0
527 stars 153 forks source link

complex json array,the result of comparison is inaccurate. #88

Closed shaozhengmao closed 5 years ago

shaozhengmao commented 5 years ago

eg.
source:[6772982,20190118,[19]] target:[6772982]

EnumSet flags = DiffFlags.dontNormalizeOpIntoMoveAndCopy().clone(); JsonNode diffResultNode = JsonDiff.asJson(actualNode, expectNode, flags); System.out.println(diffResultNode);

result: [{"op":"remove","path":"/1","value":20190118},{"op":"remove","path":"/1","value":[19]}]

i think, the result should be: [{"op":"remove","path":"/1","value":20190118},{"op":"remove","path":"/2","value":[19]}]

holograph commented 5 years ago

Sorry but you got it wrong: the patch is applied sequentially and mutates the resulting node, so referencing /2 would actually be invalid and error out (see RFC 6902 section 3: "Operations are applied sequentially in the order they appear in the array. Each operation in the sequence is applied to the target document; the resulting document becomes the target of the next operation.")

shaozhengmao commented 5 years ago

Sorry but you got it wrong: the patch is applied sequentially and mutates the resulting node, so referencing /2 would actually be invalid and error out (see RFC 6902 section 3: "Operations are applied sequentially in the order they appear in the array. Each operation in the sequence is applied to the target document; the resulting document becomes the target of the next operation.")

i get it, thanks ;)