Skip to content

Commit 2c4b2dd

Browse files
committed
backport #1604 test to 2.8
1 parent 3414458 commit 2c4b2dd

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package com.fasterxml.jackson.failing;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import com.fasterxml.jackson.databind.*;
7+
8+
// for [databind#1604]
9+
public class NestedTypes1604Test extends BaseMapTest
10+
{
11+
public static class Data<T> {
12+
private T data;
13+
14+
public Data(T data) {
15+
this.data = data;
16+
}
17+
18+
public T getData() {
19+
return data;
20+
}
21+
22+
public static <T> Data<List<T>> of(List<T> data) {
23+
return new DataList<>(data);
24+
}
25+
}
26+
27+
public static class DataList<T> extends Data<List<T>> {
28+
public DataList(List<T> data) {
29+
super(data);
30+
}
31+
}
32+
33+
public static class Inner {
34+
private int index;
35+
36+
public Inner(int index) {
37+
this.index = index;
38+
}
39+
40+
public int getIndex() {
41+
return index;
42+
}
43+
}
44+
45+
public static class BadOuter {
46+
private Data<List<Inner>> inner;
47+
48+
public BadOuter(Data<List<Inner>> inner) {
49+
this.inner = inner;
50+
}
51+
52+
public Data<List<Inner>> getInner() {
53+
return inner;
54+
}
55+
}
56+
57+
public static class GoodOuter {
58+
private DataList<Inner> inner;
59+
60+
public GoodOuter(DataList<Inner> inner) {
61+
this.inner = inner;
62+
}
63+
64+
public DataList<Inner> getInner() {
65+
return inner;
66+
}
67+
}
68+
69+
public void testIssue1604() throws Exception
70+
{
71+
final ObjectMapper objectMapper = new ObjectMapper();
72+
List<Inner> inners = new ArrayList<>();
73+
for (int i = 0; i < 2; i++) {
74+
inners.add(new Inner(i));
75+
}
76+
BadOuter badOuter = new BadOuter(Data.of(inners));
77+
// GoodOuter goodOuter = new GoodOuter(new DataList<>(inners));
78+
// String json = objectMapper.writeValueAsString(goodOuter);
79+
80+
// 11-Oct-2017, tatu: Fails with exception wrt type specialization
81+
String json = objectMapper.writeValueAsString(badOuter);
82+
assertNotNull(json);
83+
}
84+
}

0 commit comments

Comments
 (0)