Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Options ignored due to DeepEquals #51

Open
thatrobert opened this issue Mar 8, 2021 · 2 comments
Open

Options ignored due to DeepEquals #51

thatrobert opened this issue Mar 8, 2021 · 2 comments

Comments

@thatrobert
Copy link

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.

@RyanObray
Copy link

Do you have an example use case? The options you mentioned work fine in the context described in this issue: #34

@thatrobert
Copy link
Author

thatrobert commented Mar 9, 2021

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}]");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants