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

Fail to deserialize "empty" polymorphic classes #169

Closed
g8373653 opened this issue Nov 15, 2015 · 2 comments
Closed

Fail to deserialize "empty" polymorphic classes #169

g8373653 opened this issue Nov 15, 2015 · 2 comments
Milestone

Comments

@g8373653
Copy link

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)
@cowtowncoder
Copy link
Member

Yes, I can reproduce that. Will try to see what gives.

@cowtowncoder cowtowncoder changed the title deserializing empty classes and polymorphism Fail to deserialize "empty" polymorphic classes Dec 18, 2015
@cowtowncoder cowtowncoder added this to the 2.7.0-rc3 milestone Dec 18, 2015
@cowtowncoder
Copy link
Member

Ok; this is bit exotic, and needs support from jackson-databind to accept a special case of getting JsonToken.VALUE_NULL. Bit ugly, but was possible to add without ill effects; will work in 2.7.0 (can not backport fix in 2.6).

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

2 participants