Uploaded image for project: 'Johnzon'
  1. Johnzon
  2. JOHNZON-123

JSONP spec compliance: JsonNumber.hashcode() is not spec compliant

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.0.1, 1.1.3
    • None
    • None

    Description

      From the JsonNumber javadoc [1]:

      Returns the hash code value for this JsonNumber object. The hash code of a JsonNumber object is defined as the hash code of its bigDecimalValue() object.
      

      Sample application

      public final class Main {
          public static void main(String[] args) {
              JsonNumber a = Json.createObjectBuilder().add("a", 1).build().getJsonNumber("a");
              JsonNumber b = Json.createObjectBuilder().add("b", 1.1).build().getJsonNumber("b");
              
              System.out.println("Hashcode equals (a): " + (a.hashCode() == a.bigDecimalValue().hashCode()));
              System.out.println("Hashcode equals (b): " + (b.hashCode() == b.bigDecimalValue().hashCode()));
          }
      }
      

      Expected output:

      Hashcode equals (a): true
      Hashcode equals (b): true
      

      Actual output:

      Hashcode equals (a): false
      Hashcode equals (b): false
      

      [1] http://docs.oracle.com/javaee/7/api/javax/json/JsonNumber.html#hashCode--

      Attachments

        Activity

          People

            struberg Mark Struberg
            SvetlinZarev Svetlin Zarev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: