Skip to content

Commit cbd50d6

Browse files
committed
Add (failing) test for #3194
1 parent db4797e commit cbd50d6

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.fasterxml.jackson.failing;
2+
3+
import com.fasterxml.jackson.databind.BaseMapTest;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import com.fasterxml.jackson.databind.ObjectMapper.DefaultTyping;
6+
import com.fasterxml.jackson.databind.json.JsonMapper;
7+
import com.fasterxml.jackson.databind.jsontype.BasicPolymorphicTypeValidator;
8+
import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator;
9+
10+
// [databund#3194]: Discrepancy between Type Id inclusion on serialization vs
11+
// expectation during deserialization causes mismatch and fails deserialization.
12+
public class PolymorphicArrays3194Test extends BaseMapTest
13+
{
14+
static final class SomeBean {
15+
public Object[][] value;
16+
}
17+
18+
public void testTwoDimensionalArrayMapping() throws Exception
19+
{
20+
PolymorphicTypeValidator typeValidator = BasicPolymorphicTypeValidator.builder()
21+
.allowIfSubTypeIsArray()
22+
.allowIfSubType(Object.class)
23+
.build();
24+
25+
ObjectMapper mapper = JsonMapper
26+
.builder()
27+
.activateDefaultTyping(typeValidator, DefaultTyping.NON_FINAL)
28+
.build();
29+
30+
SomeBean instance = new SomeBean();
31+
instance.value = new String[][]{{"1.1", "1.2"}, {"2.1", "2.2"}};
32+
String json = mapper
33+
// .writerWithDefaultPrettyPrinter()
34+
.writeValueAsString(instance);
35+
36+
// Note: we'll see something like:
37+
//
38+
// {
39+
// "value" : [ "[[Ljava.lang.String;", [ [ "[Ljava.lang.String;", [ "1.1", "1.2" ] ], [ "[Ljava.lang.String;", [ "2.1", "2.2" ] ] ] ]
40+
// }
41+
42+
// that is, type ids for both array levels.
43+
44+
// System.err.println("JSON:\n"+json);
45+
SomeBean result = mapper.readValue(json, SomeBean.class); // fails
46+
assertEquals(String[][].class, result.value.getClass());
47+
assertEquals(String[].class, result.value[0].getClass());
48+
}
49+
}

0 commit comments

Comments
 (0)