equals()
of different numeric JsonNode
subtypes with same underlying value fails
#4343
Replies: 6 comments 1 reply
-
|
Beta Was this translation helpful? Give feedback.
-
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
providing your custom |
Beta Was this translation helpful? Give feedback.
-
@JooHyukKim As per above, there is actually a way :) |
Beta Was this translation helpful? Give feedback.
-
Ah, there is usage example Btw, this seems more like usage question. |
Beta Was this translation helpful? Give feedback.
-
Yes, good idea, this is more Discussion than issue. |
Beta Was this translation helpful? Give feedback.
-
Okay, I solved it like this now: private boolean hasEqualObject(List<ObjectNode> originalObjects, ObjectNode complexNode)
{
return originalObjects.parallelStream().anyMatch(originalNode -> {
return originalNode.equals((o1, o2) -> {
if (o1.isNumber() && o2.isNumber())
{
return o1.longValue() == o2.longValue() ? 0 : 1;
}
else
{
return o1.equals(o2) ? 0 : 1;
}
}, complexNode);
});
} Did not see the method before. But I think it would be a good thing to support this by default. It shouldn't have any bad results. As long as the int-value is cast to long for the comparison it will never result in a bad ending. So it should be a good thing to add it natively to jackson :-) |
Beta Was this translation helpful? Give feedback.
-
Search before asking
Describe the bug
Hi, I am currently struggling with a little problem when comparing 2
ObjectNodes
.The comparison of the two red-surrounded objects does fail. The reason is the
numberArray
.ObjectNode
-1 holds these values asIntNode
while
ObjectNode
-2 holds these values asLongNode
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
Beta Was this translation helpful? Give feedback.
All reactions