Skip to content

Commit aeab1e8

Browse files
author
JamesWang
committed
FasterXML#2541 Added null value test cases.
1 parent 713062f commit aeab1e8

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/test/java/com/fasterxml/jackson/databind/deser/MergePolymorphicTest.java

+18
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,24 @@ public void testPolymorphicNewObject() throws JsonProcessingException {
3838
assertEquals("I'm child A", ((ChildA) root.child).name);
3939
}
4040

41+
public void testPolymorphicFromNullToNewObject() throws JsonProcessingException {
42+
Root root = new Root();
43+
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
44+
mapper.readerForUpdating(root).readValue("{\"child\": { \"@type\": \"ChildA\", \"name\": \"I'm the new name\" }}");
45+
assertTrue(root.child instanceof ChildA);
46+
assertEquals("I'm the new name", ((ChildA) root.child).name);
47+
}
48+
49+
public void testPolymorphicFromObjectToNull() throws JsonProcessingException {
50+
Root root = new Root();
51+
ChildA childA = new ChildA();
52+
childA.name = "I'm child A";
53+
root.child = childA;
54+
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
55+
mapper.readerForUpdating(root).readValue("{\"child\": null }");
56+
assertTrue(root.child == null);
57+
}
58+
4159
public void testPolymorphicPropertyCanBeMerged() throws JsonProcessingException {
4260
Root root = new Root();
4361
ChildA childA = new ChildA();

0 commit comments

Comments
 (0)