Skip to content

Commit c62d8c7

Browse files
committed
Fix #1301
1 parent f6fbed5 commit c62d8c7

File tree

4 files changed

+49
-5
lines changed

4 files changed

+49
-5
lines changed

Diff for: release-notes/CREDITS

+4
Original file line numberDiff line numberDiff line change
@@ -463,3 +463,7 @@ Andrew Joseph (apjoseph@github)
463463
Erich Schubert (kno10@github)
464464
* Reported #1260: `NullPointerException` in `JsonNodeDeserializer`, provided fix
465465
(2.7.5)
466+
467+
Brian Pontarelli (voidmain@github)
468+
* Reported #1301: Problem with `JavaType.toString()` for recursive (self-referential) types
469+
(2.7.6)

Diff for: release-notes/VERSION

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Project: jackson-databind
1010
(reported by brentryan@github)
1111
#1279: Ensure DOM parsing defaults to not expanding external entities
1212
#1288: Type id not exposed for `JsonTypeInfo.As.EXTERNAL_PROPERTY` even when `visible` set to `true`
13+
#1301: Problem with `JavaType.toString()` for recursive (self-referential) types
14+
(reported by Brian P)
1315

1416
2.7.5 (11-Jun-2016)
1517

Diff for: src/main/java/com/fasterxml/jackson/databind/type/ResolvedRecursiveType.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,16 @@ public boolean isContainerType() {
8787

8888
@Override
8989
public String toString() {
90-
return new StringBuilder(40)
91-
.append("[resolved recursive type -> ")
92-
.append(_referencedType)
93-
.append(']')
94-
.toString();
90+
StringBuilder sb = new StringBuilder(40)
91+
.append("[recursive type; ");
92+
if (_referencedType == null) {
93+
sb.append("UNRESOLVED");
94+
} else {
95+
// [databind#1301]: Typically resolves to a loop so short-cut
96+
// and only include type-erased class
97+
sb.append(_referencedType.getRawClass().getName());
98+
}
99+
return sb.toString();
95100
}
96101

97102
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.fasterxml.jackson.failing;
2+
3+
import java.util.HashMap;
4+
5+
import com.fasterxml.jackson.databind.BaseMapTest;
6+
import com.fasterxml.jackson.databind.type.TypeFactory;
7+
8+
@SuppressWarnings("serial")
9+
public class JavaTypeDesc1301Test extends BaseMapTest
10+
{
11+
static class DataDefinition extends HashMap<String, DataDefinition> {
12+
public DataDefinition definition;
13+
public DataDefinition elements;
14+
public String regex;
15+
public boolean required;
16+
public String type;
17+
}
18+
19+
// for [databind#1301]
20+
public void testJavaTypeToString() throws Exception
21+
{
22+
TypeFactory tf = objectMapper().getTypeFactory();
23+
String desc = tf.constructType(DataDefinition.class).toString();
24+
assertNotNull(desc);
25+
// could try comparing exact message, but since it's informational try looser:
26+
if (!desc.contains("map type")) {
27+
fail("Description should contain 'map type', did not: "+desc);
28+
}
29+
if (!desc.contains("recursive type")) {
30+
fail("Description should contain 'recursive type', did not: "+desc);
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)