File tree 1 file changed +18
-0
lines changed
src/test/java/com/fasterxml/jackson/databind/deser
1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,24 @@ public void testPolymorphicNewObject() throws JsonProcessingException {
38
38
assertEquals ("I'm child A" , ((ChildA ) root .child ).name );
39
39
}
40
40
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
+
41
59
public void testPolymorphicPropertyCanBeMerged () throws JsonProcessingException {
42
60
Root root = new Root ();
43
61
ChildA childA = new ChildA ();
You can’t perform that action at this time.
0 commit comments