1
1
package com .fasterxml .jackson .databind .type ;
2
2
3
+ import java .util .ArrayList ;
3
4
import java .util .List ;
4
5
5
6
import com .fasterxml .jackson .annotation .JsonCreator ;
11
12
12
13
public class RecursiveWildcardTest extends BaseMapTest
13
14
{
14
- public void test () throws Exception
15
- {
16
- ObjectMapper mapper = newJsonMapper ();
17
-
18
- Tree <?> tree = mapper .readValue ("[[[]]]" , new TypeReference <Tree <?>>() {
19
- });
20
-
21
- assertEquals (1 , tree .children .size ());
22
- assertEquals (1 , tree .children .get (0 ).children .size ());
23
- assertEquals (0 , tree .children .get (0 ).children .get (0 ).children .size ());
24
- }
25
-
26
- public static class Tree <T extends Tree <?>> {
15
+ static class Tree <T extends Tree <?>> {
27
16
28
17
final List <T > children ;
29
18
@@ -35,6 +24,63 @@ public Tree(List<T> children) {
35
24
}
36
25
this .children = children ;
37
26
}
27
+ }
28
+
29
+ static class TestAttribute4118 <T extends TestAttribute4118 <?>> {
30
+
31
+ public List <T > attributes ;
32
+
33
+ public TestAttribute4118 () { }
34
+
35
+ public TestAttribute4118 (List <T > attributes ) {
36
+ this .attributes = attributes ;
37
+ }
38
+ }
39
+
40
+ static class TestObject4118 {
41
+
42
+ public List <TestAttribute4118 <?>> attributes = new ArrayList <>();
43
+
44
+ public TestObject4118 () { }
45
+
46
+ public TestObject4118 (List <TestAttribute4118 <?>> attributes ) {
47
+ this .attributes = attributes ;
48
+ }
49
+ }
50
+
51
+ private final ObjectMapper MAPPER = newJsonMapper ();
52
+
53
+ public void testRecursiveWildcard () throws Exception
54
+ {
55
+ Tree <?> tree = MAPPER .readValue ("[[[]]]" , new TypeReference <Tree <?>>() {
56
+ });
57
+
58
+ assertEquals (1 , tree .children .size ());
59
+ assertEquals (1 , tree .children .get (0 ).children .size ());
60
+ assertEquals (0 , tree .children .get (0 ).children .get (0 ).children .size ());
61
+ }
62
+
63
+ // for [databind#4118]
64
+ public void testDeserWildcard4118 () throws Exception
65
+ {
66
+ // Given
67
+ TestAttribute4118 a = new TestAttribute4118 (null );
68
+ TestAttribute4118 b = new TestAttribute4118 (_listOf (a ));
69
+ TestAttribute4118 c = new TestAttribute4118 (_listOf (b ));
70
+ TestObject4118 test = new TestObject4118 (_listOf (c ));
71
+
72
+ String serialized = MAPPER .writeValueAsString (test );
73
+
74
+ // When
75
+ TestObject4118 deserialized = MAPPER .readValue (serialized , TestObject4118 .class );
76
+
77
+ // Then
78
+ assertType (deserialized .attributes .get (0 ).attributes .get (0 ), TestAttribute4118 .class );
79
+ }
38
80
81
+ private <T > List <T > _listOf (T elem ) {
82
+ ArrayList <T > list = new ArrayList <>();
83
+ list .add (elem );
84
+ return list ;
39
85
}
40
86
}
0 commit comments