Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String property deserializes null as "null" for JsonTypeInfo.As.EXTERNAL_PROPERTY #3008

Closed
cowtowncoder opened this issue Jan 5, 2021 · 0 comments
Milestone

Comments

@cowtowncoder
Copy link
Member

(note: copied from FasterXML/jackson-module-kotlin#335)

Looks like following test case, first found with Kotlin, fails:

public class ExternalPropertyTypeShouldBeNullTest {

    static class Box {
        public String type;
        public Fruit fruit;

        public Box(@JsonProperty("type") String type,

                   @JsonTypeInfo(use = Id.NAME, include = As.EXTERNAL_PROPERTY, property = "type")
                   @JsonSubTypes({@Type(value = Orange.class, name = "orange")})
                   @JsonProperty("fruit") Fruit fruit) {
            this.type = type;
            this.fruit = fruit;
        }
    }

    interface Fruit{}

    static class Orange implements Fruit {
        public String name;
        public String color;

        public Orange(@JsonProperty("name") String name, @JsonProperty("name") String color) {
            this.name = name;
            this.color = color;
        }
    }

    private final ObjectMapper MAPPER = new ObjectMapper();

    @Test
    public void testDeserializationNull() throws Exception {
        MAPPER.disable(DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY);
        Box deserOrangeBox = MAPPER.readValue("{\"type\":null,\"fruit\":null}}", Box.class);
        assertNull(deserOrangeBox.fruit);
        assertNull(deserOrangeBox.type); // error: "expected null, but was:<null>"
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant