You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@johnzon.apache.org by "Romain Manni-Bucau (JIRA)" <ji...@apache.org> on 2017/06/06 09:22:18 UTC

[jira] [Commented] (JOHNZON-124) JsonArrayImpl should not override equals method

    [ https://issues.apache.org/jira/browse/JOHNZON-124?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16038443#comment-16038443 ] 

Romain Manni-Bucau commented on JOHNZON-124:
--------------------------------------------

[~kal0ian] we respect that, the list "reference" is cause JsonArray is a list (http://docs.oracle.com/javaee/7/api/javax/json/JsonArray.html) but equals should also enforce you don't have an element of another type and is symmetric so IMHO expectations are:

{code}
list.equals(jsonArray) == false
jsonArray.equals(list) == false
jsonArrayRI.equals(jsonArrayJohnzon) == true
jsonArrayJohnzon.equals(jsonArrayRI) == true
{code}

Also being said there is no way in the spec to get a List<JsonValue> I'm not sure it is a concern.

> JsonArrayImpl should not override equals method
> -----------------------------------------------
>
>                 Key: JOHNZON-124
>                 URL: https://issues.apache.org/jira/browse/JOHNZON-124
>             Project: Johnzon
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 1.0.0
>            Reporter: Kaloyan Spiridonov
>            Assignee: Romain Manni-Bucau
>             Fix For: 1.1.2
>
>
> According to javadoc the equals method of JsonArray should be inherited from List.  The javadoc of java.util.List.equals(Object o) says:
> {quote}
> 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.
> {quote}
> The following code:
> {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));
> {code}
> 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.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)