File tree 4 files changed +49
-5
lines changed
main/java/com/fasterxml/jackson/databind/type
test/java/com/fasterxml/jackson/failing
4 files changed +49
-5
lines changed Original file line number Diff line number Diff line change @@ -463,3 +463,7 @@ Andrew Joseph (apjoseph@github)
463
463
Erich Schubert (kno10@github)
464
464
* Reported #1260: `NullPointerException` in `JsonNodeDeserializer`, provided fix
465
465
(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)
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ Project: jackson-databind
10
10
(reported by brentryan@github)
11
11
#1279: Ensure DOM parsing defaults to not expanding external entities
12
12
#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)
13
15
14
16
2.7.5 (11-Jun-2016)
15
17
Original file line number Diff line number Diff line change @@ -87,11 +87,16 @@ public boolean isContainerType() {
87
87
88
88
@ Override
89
89
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 ();
95
100
}
96
101
97
102
@ Override
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments