Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

equals() of different numeric JsonNode subtypes with same underlying value fails #4342

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

Closed
1 task done
Captain-P-Goldfish opened this issue Jan 25, 2024 · 5 comments
Closed
1 task done
Labels
to-evaluate Issue that has been received but not yet evaluated

Comments

@Captain-P-Goldfish
Copy link

Captain-P-Goldfish commented Jan 25, 2024

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

Hi, I am currently struggling with a little problem when comparing 2 ObjectNodes.

comparisonFailure

The comparison of the two red-surrounded objects does fail. The reason is the numberArray.
ObjectNode-1 holds these values as IntNode
while
ObjectNode-2 holds these values as LongNode

would it be possible to adjust the comparison to let them match by value instead of type and value?

Version Information

2.16.0

Reproduction

see above

Expected behavior

comparison succeeds

Additional context

No response

@Captain-P-Goldfish Captain-P-Goldfish added the to-evaluate Issue that has been received but not yet evaluated label Jan 25, 2024
@JooHyukKim
Copy link
Member

JooHyukKim commented Jan 25, 2024

I don't think there's such an option nor the comparison methods are overridable. 🤔

@cowtowncoder
Copy link
Member

This is one area where it is quite impractical to try to coerce values to make different number types match, so no attempt is made. This has been extensively discussed in the past.

However, there IS a way to customize this by calling this method on JsonNode:

public boolean equals(Comparator<JsonNode> comparator, JsonNode other);

providing your custom Comparator<JsonNode> implementation, which may then use whatever coercion/conversion rules you want. It is meant to allow solving this particular problem.

@cowtowncoder cowtowncoder changed the title Comparison Failure on equals equals() of different numeric JsonNode subtypes with same underlying value fails Jan 26, 2024
@cowtowncoder
Copy link
Member

@JooHyukKim As per above, there is actually a way :)

@JooHyukKim
Copy link
Member

@JooHyukKim As per above, there is actually a way :)

Ah, there is usage example

Btw, this seems more like usage question.
Should we transfer this to Dicussions tab, @cowtowncoder ?

@cowtowncoder
Copy link
Member

Yes, good idea, this is more Discussion than issue.

@FasterXML FasterXML locked and limited conversation to collaborators Jan 26, 2024
@cowtowncoder cowtowncoder converted this issue into discussion #4343 Jan 26, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
to-evaluate Issue that has been received but not yet evaluated
Projects
None yet
Development

No branches or pull requests

3 participants