jsondiffpatch.net icon indicating copy to clipboard operation
jsondiffpatch.net copied to clipboard

Options ignored due to DeepEquals

Open thatrobert opened this issue 3 years ago • 2 comments

The features supported in Options like ExcludePath and DiffBehaviors are effectively ignored since JToken.DeepEquals doesn't take those into account.

If you exclude a path that would show up in an DeepEquals array scan, DeepEquals will still return false, even if every other path is valid. The same thing for IgnoreMissingProperties or IgnoreNewProperties.

Assuming you're not interested in writing your own DeepEquals, building an interface around that so that users can write their own would be helpful.

thatrobert avatar Mar 08 '21 23:03 thatrobert

Do you have an example use case? The options you mentioned work fine in the context described in this issue: https://github.com/wbish/jsondiffpatch.net/issues/34

RyanObray avatar Mar 09 '21 01:03 RyanObray

var json1 = (JToken)JsonConvert.DeserializeObject("[{\"id\":1,\"data\":100},{\"id\":2,\"data\":200},{\"id\":3,\"data\":300}]"); var json2 = (JToken)JsonConvert.DeserializeObject("[{\"id\":2,\"data\":200},{\"id\":3,\"data\":300}]"); Options options = new Options() { DiffBehaviors = DiffBehavior.IgnoreNewProperties }; var jdb = new JsonDiffPatch(); var patch = jdb.Diff(json1, json2);

If you run this, you'll see Diff will simply delete id 1 as expected. Add another property like so and you'll get very different results, despite the fact that IgnoreNewProperties is set.

var json2 = (JToken)JsonConvert.DeserializeObject("[{\"id\":2,\"data\":200,\"more\":20},{\"id\":3,\"data\":300}]");

thatrobert avatar Mar 09 '21 02:03 thatrobert