Skip to content

Commit da3755a

Browse files
committed
#72 Any support equals and hashcode
1 parent e7d60a5 commit da3755a

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.jsoniter</groupId>
6-
<version>0.9.13</version>
6+
<version>0.9.14-SNAPSHOT</version>
77
<artifactId>jsoniter</artifactId>
88
<name>json iterator</name>
99
<description>jsoniter (json-iterator) is fast and flexible JSON parser available in Java and Go</description>

src/main/java/com/jsoniter/any/Any.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,4 +333,22 @@ public static Any rewrap(Map<String, Any> val) {
333333
protected boolean isWildcard(Object key) {
334334
return wildcardHashCode == key.hashCode() && wildcard.equals(key);
335335
}
336+
337+
@Override
338+
public boolean equals(Object o) {
339+
if (this == o) return true;
340+
if (o == null || getClass() != o.getClass()) return false;
341+
342+
Any any = (Any) o;
343+
344+
Object obj = this.object();
345+
Object thatObj = any.object();
346+
return obj != null ? obj.equals(thatObj) : thatObj == null;
347+
}
348+
349+
@Override
350+
public int hashCode() {
351+
Object obj = this.object();
352+
return obj != null ? obj.hashCode() : 0;
353+
}
336354
}

src/test/java/com/jsoniter/any/TestArray.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,11 @@ public void test_fill_partial_then_iterate() {
6363
assertEquals(3, iter.next().toInt());
6464
assertFalse(iter.hasNext());
6565
}
66+
67+
public void test_equals_and_hashcode() {
68+
Any obj1 = JsonIterator.deserialize("[1,2,3]");
69+
Any obj2 = JsonIterator.deserialize("[1, 2, 3]");
70+
assertEquals(obj1, obj2);
71+
assertEquals(obj1.hashCode(), obj2.hashCode());
72+
}
6673
}

0 commit comments

Comments
 (0)