-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
LeakyAbstraction: NumericNodes which represent the same Json value are not considered equal #4803
Comments
Ok, first, I disagree on specific ask wrt But! Back then we last thought about this problem (there is likely closed old issue for this, will try to find it), we added this method in
in But the logical question, then, is whether Jackson project should offer an implementation that did use full equality as you described. |
For context we have previous issues:
as well as issue for which alternate So this is definitely something users find challenging. But as I said, I think the path forward would be with providing "Number canonicalizing"
Having said that, to get progress, a PR would probably be needed. |
Yeah, the suggested equals method would do 👍🏼 public boolean equals(Comparator<JsonNode> comparator, JsonNode other) { Otherwise, you're welcome to read through mentioned issues by @cowtowncoder above and help come up with solution -- that hopefully satisfies every(or most) user's need. Saying this because you mentioned leaky abstraction and I think we can also say that JSON number specification itself is leaky. Converting from fine grained expression to rough is easy, but not the way around. |
I think a |
@yawkat That would be delightfully simple implementation indeed. So then it'd be just the question of plugging it in API. As I said I do not think it'd be good for |
Describe the bug
Hi everyone.
when converting a java object to a JsonNode tree, depending on the underlying implementation chosen, the resulting Json trees are not considered equal, even though they represent the same Json value and serialize to the same Json string representation.
I.e. an IntNode representing 12345 is not equal to a LongNode, ShortNode, BigIntegerNode or DecimalNode representing the same value.
If I deserialize these nodes and compare the resulting Json string, they are considered equal.
This is a case of leaky abstraction.
Use case is:
When testing a class producing Json output, I want to compare the produced Json to a reference json to check correctness of the implementation.
Version Information
2.17.1
Reproduction
Expected behavior
According to my expectation JsonNode trees representing the same Json String are also considered equal and do not differ in equality based on internal (implementation) details.
I do understand that for float and double this might not always hold since there -depending on precision- they may yield differing results.
Current workaround in JunitTests before comparing json result trees with the respective expected reference json:
Though this workaround adds considerable computational overhead for the (imho unnecessary) additional deserialisation step required.
The text was updated successfully, but these errors were encountered: