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

JsonArrayImpl should not override equals method

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Won't Fix
    • 1.0.0
    • 1.1.2
    • Core
    • None

    Description

      According to javadoc the equals method of JsonArray should be inherited from List. The javadoc of java.util.List.equals(Object o) says:

      Compares the specified object with this list for equality. Returns true if and only if the specified object is also a list, both lists have the same size, and all corresponding pairs of elements in the two lists are equal. (Two elements e1 and e2 are equal if (e1==null ? e2==null : e1.equals(e2)).) In other words, two lists are defined to be equal if they contain the same elements in the same order. This definition ensures that the equals method works properly across different implementations of the List interface.

      The following code:

      JsonReader reader = Json.createReader(new StringReader("[true]"));
      	    JsonArray jsonArray = reader.readArray();
          	List<JsonValue> actList = jsonArray;
          	
          	List<JsonValue> list = new ArrayList<JsonValue>();
           	list.add(JsonValue.TRUE);
          	System.out.println(actList.equals(list));
      

      should return true instead of false.

      One fix will be just to remove the equals method from JsonArrayImpl and then the AbstractList<E>.equals(Object paramObject) will be used.

      Attachments

        Activity

          People

            romain.manni-bucau Romain Manni-Bucau
            kal0ian Kaloyan Spiridonov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: