Skip to content

JsonNumEquals fails to compare IntNode and LongNode with same value #45

Open
@grimsa

Description

@grimsa

Problem

JsonNode intNode = IntNode.valueOf(1);
JsonNode longNode = LongNode.valueOf(1);
boolean same = JsonNumEquals.getInstance().equivalent(intNode, longNode);
// at this point same == false

Cause
In com.github.fge.jackson.JsonNumEquals#numEquals:

private static boolean numEquals(final JsonNode a, final JsonNode b)
{
    /*
     * If both numbers are integers, delegate to JsonNode.
     */
    if (a.isIntegralNumber() && b.isIntegralNumber())     // this is true
        return a.equals(b);           // yet this is false

    /*
     * Otherwise, compare decimal values.
     */
    return a.decimalValue().compareTo(b.decimalValue()) == 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions