Skip to content

Commit 075319d

Browse files
committed
Fix #1658
1 parent dc2c003 commit 075319d

File tree

4 files changed

+68
-4
lines changed

4 files changed

+68
-4
lines changed

release-notes/CREDITS

+5
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,11 @@ Bertrand Renuart (brenuart@github)
629629
* Reported #1651: `StdDateFormat` fails to parse 'zulu' date when TimeZone other than UTC
630630
(2.8.9)
631631

632+
Kevin Gallardo (newkek@github)
633+
* Reported #1658: Infinite recursion when deserializing a class extending a Map,
634+
with a recursive value type
635+
(2.8.10)
636+
632637
Connor Kuhn (ckuhn@github)
633638
* Contributed #1341: FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY
634639
(2.9.0)

release-notes/VERSION

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Project: jackson-databind
88
#1657: `StdDateFormat` deserializes dates with no tz/offset as UTC instead of
99
configured timezone
1010
(reported by Bertrand R)
11+
#1658: Infinite recursion when deserializing a class extending a Map,
12+
with a recursive value type
13+
(reported by Kevin G)
1114

1215
2.8.9 (12-Jun-2017)
1316

src/main/java/com/fasterxml/jackson/databind/type/ResolvedRecursiveType.java

+15-4
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,22 @@ public String toString() {
111111
public boolean equals(Object o) {
112112
if (o == this) return true;
113113
if (o == null) return false;
114-
// Do NOT ever match unresolved references
115-
if (_referencedType == null) {
114+
if (o.getClass() == getClass()) {
115+
// 16-Jun-2017, tatu: as per [databind#1658], can not do recursive call since
116+
// there is likely to be a cycle...
117+
118+
// but... true or false?
116119
return false;
120+
121+
/*
122+
// Do NOT ever match unresolved references
123+
if (_referencedType == null) {
124+
return false;
125+
}
126+
return (o.getClass() == getClass()
127+
&& _referencedType.equals(((ResolvedRecursiveType) o).getSelfReferencedType()));
128+
*/
117129
}
118-
return (o.getClass() == getClass()
119-
&& _referencedType.equals(((ResolvedRecursiveType) o).getSelfReferencedType()));
130+
return false;
120131
}
121132
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.fasterxml.jackson.databind.type;
2+
3+
import java.util.*;
4+
5+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
6+
import com.fasterxml.jackson.databind.*;
7+
import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder;
8+
import com.fasterxml.jackson.databind.jsontype.impl.StdTypeResolverBuilder;
9+
10+
public class RecursiveType1658Test extends BaseMapTest
11+
{
12+
@SuppressWarnings("serial")
13+
static class Tree<T> extends HashMap<T, Tree<T>> // implements Serializable
14+
{
15+
public Tree() { }
16+
17+
public Tree(List<T> children) {
18+
this();
19+
for (final T t : children) {
20+
this.put(t, new Tree<T>());
21+
}
22+
}
23+
24+
public List<Tree<T>> getLeafTrees() {
25+
return null;
26+
}
27+
}
28+
29+
public void testRecursive1658() throws Exception
30+
{
31+
Tree<String> t = new Tree<String>(Arrays.asList("hello", "world"));
32+
ObjectMapper mapper = new ObjectMapper();
33+
34+
final TypeResolverBuilder<?> typer = new StdTypeResolverBuilder()
35+
.init(JsonTypeInfo.Id.CLASS, null)
36+
.inclusion(JsonTypeInfo.As.PROPERTY);
37+
mapper.setDefaultTyping(typer);
38+
39+
String res = mapper.writeValueAsString(t);
40+
41+
Tree<?> tRead = mapper.readValue(res, Tree.class);
42+
43+
assertNotNull(tRead);
44+
}
45+
}

0 commit comments

Comments
 (0)