Skip to content

Commit 9a233d9

Browse files
committed
unit test improvement (wrt #312)
1 parent 540213f commit 9a233d9

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/test/java/com/fasterxml/jackson/failing/TestOverlappingTypeIdNames312.java

+26-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.fasterxml.jackson.annotation.JsonSubTypes;
44
import com.fasterxml.jackson.annotation.JsonTypeInfo;
5-
5+
import com.fasterxml.jackson.annotation.JsonTypeName;
66
import com.fasterxml.jackson.databind.*;
77

88
public class TestOverlappingTypeIdNames312 extends BaseMapTest
@@ -17,22 +17,43 @@ static abstract class Base312 { }
1717
static class Impl312 extends Base312 {
1818
public int x;
1919
}
20-
20+
21+
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
22+
@JsonSubTypes({
23+
@JsonSubTypes.Type(name = "a", value = Impl312B1.class),
24+
@JsonSubTypes.Type(name = "a", value = Impl312B2.class)
25+
})
26+
static class Base312B {
27+
public int value = 1;
28+
}
29+
30+
static class Impl312B1 extends Base312B { }
31+
static class Impl312B2 extends Base312B { }
32+
33+
final ObjectMapper MAPPER = objectMapper();
34+
2135
public void testOverlappingNameDeser() throws Exception
2236
{
23-
final ObjectMapper mapper = objectMapper();
2437
Base312 value;
2538

2639
// Ensure both type ids are acceptable
2740

28-
value = mapper.readValue(aposToQuotes("{'type':'a','x':7}"), Base312.class);
41+
value = MAPPER.readValue(aposToQuotes("{'type':'a','x':7}"), Base312.class);
2942
assertNotNull(value);
3043
assertEquals(Impl312.class, value.getClass());
3144
assertEquals(7, ((Impl312) value).x);
3245

33-
value = mapper.readValue(aposToQuotes("{'type':'b','x':3}"), Base312.class);
46+
value = MAPPER.readValue(aposToQuotes("{'type':'b','x':3}"), Base312.class);
3447
assertNotNull(value);
3548
assertEquals(Impl312.class, value.getClass());
3649
assertEquals(3, ((Impl312) value).x);
3750
}
51+
52+
public void testOverlappingNameSer() throws Exception
53+
{
54+
assertEquals(aposToQuotes("{'type':'a','value':1}"),
55+
MAPPER.writeValueAsString(new Impl312B1()));
56+
assertEquals(aposToQuotes("{'type':'a','value':1}"),
57+
MAPPER.writeValueAsString(new Impl312B2()));
58+
}
3859
}

0 commit comments

Comments
 (0)