-
-
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
Add JsonNode.equals(Comparator<JsonNode>, JsonNode)
to support configurable/external equality comparison
#790
Milestone
Comments
cowtowncoder
changed the title
Add
Add May 13, 2015
JsonNode.equals(Comparator<JsonNode>)
to support configurable/external equality comparisonJsonNode.equals(Comparator<JsonNode>, JsonNode)
to support configurable/external equality comparison
cowtowncoder
added a commit
that referenced
this issue
May 13, 2015
Ok: as per unit test: public void testCustomComparators() throws Exception
{
ObjectNode root1 = MAPPER.createObjectNode();
root1.put("value", 5);
ObjectNode root2 = MAPPER.createObjectNode();
root2.put("value", 5.0);
// default equals(): not strictly equal
assertFalse(root1.equals(root2));
// but. Custom comparator can make all the difference
Comparator<JsonNode> cmp = new Comparator<JsonNode>() {
@Override
public int compare(JsonNode o1, JsonNode o2) {
if (o1.equals(o2)) {
return 0;
}
if ((o1 instanceof NumericNode) && (o2 instanceof NumericNode)) {
double d1 = ((NumericNode) o1).asDouble();
double d2 = ((NumericNode) o2).asDouble();
if (d1 == d2) { // strictly equals because it's integral value
return 1;
}
}
return 0;
}
};
// but with custom comparator, yes
assertTrue(root1.equals(cmp, root2)); |
@fge Not sure if it's relevant any more, but I think you wanted more easily configurable comparison. This addition in 2.6 will allow defining simple scalar comparators, and handle Array/Object traversal. |
1 task
Closed
1 task
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Since it is difficult to make default
JsonNode.equals(Object)
work "perfectly" (cover all use cases users have), partly because there is no way to configure this handling (no way to pass context/config info, for example), it may make more sense to add a way to use customComparator
s.The only real functionality in databinding, then, would be traversal of
ArrayNode
s andObjectNode
s, to handle structural part; but use passed-in comparator object for scalar value comparisons.The text was updated successfully, but these errors were encountered: