-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Milestone
Description
Describe the bug
When using JsonTypeInfo.As.EXISTING_PROPERTY to deserialize String properties, a null value is being deserialized as "null"
Version information
2.12.2
To Reproduce
If you have a way to reproduce this with:
public class ExistingPropertyShouldBeNullTest {
@JsonTypeInfo(use = Id.NAME, include = As.EXISTING_PROPERTY, visible = true, property = "type", defaultImpl = DefaultShape.class)
@JsonSubTypes({@Type(value = Square.class, name = "square")})
static abstract class Shape {
public String type;
public String getType() { return this.type; }
public void setType(String type) { this.type = type; }
}
static class Square extends Shape {}
static class DefaultShape extends Shape {}
private final ObjectMapper MAPPER = new ObjectMapper();
@Test
public void testDeserializationWithValidType() throws Exception {
Shape deserShape = MAPPER.readValue("{\"type\":\"square\"}", Shape.class);
assertEquals("square", deserShape.getType());
}
@Test
public void testDeserializationWithInvalidType() throws Exception {
Shape deserShape = MAPPER.readValue("{\"type\":\"invalid\"}", Shape.class);
assertEquals("invalid", deserShape.getType());
}
@Test
public void testDeserializationNull() throws Exception {
Shape deserShape = MAPPER.readValue("{\"type\":null}", Shape.class);
assertNull(deserShape.getType()); // error: "expected null, but was:<null>"
}
}
Expected behavior
The String property should be deserialized to a literal null when null is passed in
Additional context
Similar to #3008, but using EXISTING_PROPERTY instead. Abstraction is also used in the above code example
Metadata
Metadata
Assignees
Labels
No labels