Skip to content

Fail to deserialize "empty" polymorphic classes #169

@g8373653

Description

@g8373653

I found a problem with deserializing empty classes in combination with polymorphism. The issue can also be found on SO: http://stackoverflow.com/questions/33722369/jackson-xml-deserializing-empty-classes-and-polymorphism

The problem happens both with JAXB and Jackson XML annotations. I pasted the XML example below:

public static class Data {
    @XmlElement(name = "name")
    private String name;
    @XmlElements({
            @XmlElement(type = EmptyProxy.class, name = "empty")
    })
    private Proxy  proxy;
}

public interface Proxy {
}

@XmlType(name = "empty")
public static class EmptyProxy implements Proxy {
}

public static void main(String[] a) throws IOException {
    final ObjectMapper mapper = new XmlMapper()/*.registerModule(new JacksonXmlModule())*/.registerModule(new JaxbAnnotationModule());
    final Data data = mapper.readValue("<data><name>my-name</name><proxy><empty></empty></proxy></data>", Data.class);
}

This gives the following exeption:

Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of Test$EmptyProxy out of VALUE_NULL token
 at [Source: java.io.StringReader@27c20538; line: 1, column: 49] (through reference chain: Data["proxy"])
    at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:148)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions