Skip to content

Commit de92568

Browse files
committed
Modify test to use inclusion as expected
1 parent e374faa commit de92568

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

src/test/java/com/fasterxml/jackson/databind/deser/jdk/AtomicReferenceWithStdTypeResolverBuilder4838Test.java

+30-11
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public boolean equals(Object obj) {
6969
}
7070
}
7171

72-
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY)
72+
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.WRAPPER_ARRAY)
7373
static abstract class Animal2 {
7474
public String name;
7575

@@ -92,34 +92,53 @@ public boolean equals(Object obj) {
9292

9393
@Test
9494
public void testRoundTrip() throws Exception {
95-
_test(new AtomicReference<>("MyName"), String.class);
96-
_test(new AtomicReference<>(42), Integer.class);
97-
_test(new AtomicReference<>(Pojo86.valueOf("PojoName")), Pojo86.class);
95+
_test(new AtomicReference<>("MyName"), String.class,
96+
STD_RESOLVER_MAPPER_WRAPPER_OBJECT);
97+
_test(new AtomicReference<>(42), Integer.class,
98+
STD_RESOLVER_MAPPER_WRAPPER_OBJECT);
99+
_test(new AtomicReference<>(Pojo86.valueOf("PojoName")), Pojo86.class,
100+
STD_RESOLVER_MAPPER_WRAPPER_OBJECT);
98101
}
99102

100103
@Test
101104
public void testPolymorphic() throws Exception {
102-
_test(new AtomicReference<>(new Dog("Buddy")), Animal.class);
103-
_test(new AtomicReference<>(new Dog2("Buttercup")), Animal2.class);
105+
_test(new AtomicReference<>(new Dog("Buddy")), Animal.class,
106+
STD_RESOLVER_MAPPER_WRAPPER_OBJECT);
104107
}
105108

106-
private final ObjectMapper STD_RESOLVER_MAPPER = jsonMapperBuilder()
109+
@Test
110+
public void testPolymorphic2() throws Exception {
111+
_test(new AtomicReference<>(new Dog2("Buttercup")), Animal2.class,
112+
STD_RESOLVER_MAPPER_WRAPPER_ARRAY);
113+
}
114+
115+
private final ObjectMapper STD_RESOLVER_MAPPER_WRAPPER_OBJECT = jsonMapperBuilder()
107116
// this is what's causing failure in later versions.....
108117
.setDefaultTyping(
109118
new StdTypeResolverBuilder()
110119
.init(JsonTypeInfo.Id.CLASS, null)
111120
.inclusion(JsonTypeInfo.As.WRAPPER_OBJECT)
112121
).build();
113122

114-
private <T> void _test(AtomicReference<T> value, Class<?> type) throws Exception {
123+
private final ObjectMapper STD_RESOLVER_MAPPER_WRAPPER_ARRAY = jsonMapperBuilder()
124+
// this is what's causing failure in later versions.....
125+
.setDefaultTyping(
126+
new StdTypeResolverBuilder()
127+
.init(JsonTypeInfo.Id.CLASS, null)
128+
.inclusion(JsonTypeInfo.As.WRAPPER_ARRAY)
129+
).build();
130+
131+
private <T> void _test(AtomicReference<T> value, Class<?> type, ObjectMapper mapper)
132+
throws Exception
133+
{
115134
// Serialize
116135
Foo<T> foo = new Foo<>();
117136
foo.value = value;
118-
String json = STD_RESOLVER_MAPPER.writeValueAsString(foo);
137+
String json = mapper.writeValueAsString(foo);
119138

120139
// Deserialize
121-
Foo<T> bean = STD_RESOLVER_MAPPER.readValue(json,
122-
STD_RESOLVER_MAPPER.getTypeFactory().constructParametricType(Foo.class, type));
140+
Foo<T> bean = mapper.readValue(json,
141+
mapper.getTypeFactory().constructParametricType(Foo.class, type));
123142

124143
// Compare the underlying values of AtomicReference
125144
assertEquals(foo.value.get(), bean.value.get());

0 commit comments

Comments
 (0)