-
Notifications
You must be signed in to change notification settings - Fork 14
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
SuppressDetectArrayMove does not work as expected #38
Comments
I don' think |
Thanks @weichch. I tried this:
|
Array diff is a bit complex. The generated diff (in your case In your case you have two complex objects in the array: You could try sort the array before calling If this isn't an option, you might need to override the array item diffing behavior by implementing your own For example, below code would make two objects identical when they both contain a property
For example, in these two arrays |
Thank you for the detailed explanation. It makes sense, but would be nice to have an option that "properly" ignores array order. Two arrays are equal if:
Is such option possible but has not been implemented, or does it have some logical problem I'm not seeing? |
From JSON definition's perspective, the order of elements in an array shouldn't be ignored. In RFC 7159:
From a functional perspective, sure, it can be done but need more thinking.
We will have to consider duplicates here. For example, the arrays below meet the rules 1 & 2, but the two aren't necessarily equal. It is likely we need to sort the arrays before comparing them or verify that they both contain the same elements.
Both approaches require the caller to pass in a hash/comparer function for complex objects. |
Yes I can see the problem with my logic of comparing arrays based on your above example. Sorting is probably not an option if we do not want to require passing in a hash/comparer function. When we do "For each element in |
If the approach is checking whether left contains right and then right contains left, then tracking the comparison result is going to improve the performance by avoiding comparing same set of elements twice. There are also other approaches such as hashing:
In this approach, left can be appended to the dictionary with the However, this approach requires a hash function to work as we can't rely on the default Another thing we'd also need to consider is if we do provide an option to disable checking for order of elements, then it is likely we need to implement this in
We might have to keep the materialized |
Do you mind (me) changing the title of this issue to something like "Compare two arrays ignoring order" because I thought it is what we're discussing here and the topic is useful. |
Yes definitely. I thought Regarding the exact |
Steps to reproduce:
Either
SuppressDetectArrayMove
does not work, or I misunderstood what it does? I this case how can I configureJsonDiffPatcher
to ignore array element order?The text was updated successfully, but these errors were encountered: