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

Improve JsonNode.DeepEquals numeric equality. #104255

Merged

Conversation

eiriktsarpalis
Copy link
Member

@eiriktsarpalis eiriktsarpalis commented Jul 1, 2024

The JsonNode.DeepEquals implementation currently uses UTF-8 sequence equality when determining if two JSON numbers are equal. This means that under the current semantics 1.0 != 1 and -0.0 != 0.

Following feedback from @gregsdennis I put up this PR that attempts to derive numeric equality from decimal. This approach has its own share of problems though because we currently have no way of handling numeric values not representable by decimal, so it still needs to fallback to sequence equality (a BigDecimal type might have been useful in this case).

Fix #97490.

Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation-wise, LGTM. I defer to @tannergooding about appropriateness.

@gregsdennis
Copy link
Contributor

Relates to #97490

@eiriktsarpalis eiriktsarpalis changed the title Attempt at improving JsonNode.DeepEquals numeric equality. Improve JsonNode.DeepEquals numeric equality. Jul 2, 2024
@eiriktsarpalis
Copy link
Member Author

@tannergooding would it be possible to take another look at this?

@eiriktsarpalis eiriktsarpalis merged commit 90d4c7d into dotnet:main Jul 8, 2024
81 of 83 checks passed
@eiriktsarpalis eiriktsarpalis deleted the jsonelement-numeric-comparison branch July 8, 2024 16:58
@github-actions github-actions bot locked and limited conversation to collaborators Aug 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JsonNode.DeepEquals() erroneously considers number representation
4 participants