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

Jackson fails to read XML file it writes based on JAXB annotations #362

Closed
rpatrick00 opened this issue Nov 16, 2015 · 4 comments
Closed

Comments

@rpatrick00
Copy link

I have a simple test at https://github.com/rpatrick00/jackson-polymorphic-test where I am trying to use polymorphic types using JAXB annotations. The code works fine with straight JAXB but Jackson 2.6.3 is failing to read the file that it wrote. The file that Jackson with JAXB annotations wrote looks like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<company>
    <computers>
        <desktop id="computer-1">
            <location>Bangkok</location>
        </desktop>
        <desktop id="computer-2">
            <location>Pattaya</location>
        </desktop>
        <laptop id="computer-3">
            <vendor>Apple</vendor>
        </laptop>
    </computers>
</company>

When trying to use Jackson to read the file back in, it fails with the following:

Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: Unexpected token (FIELD_NAME), expected START_OBJECT: need JSON Object to contain As.WRAPPER_OBJECT type information for class test.Computer
 at [Source: company-jackson.xml; line: 4, column: 9] (through reference chain: test.Company["computers"]->java.util.ArrayList[0])
    at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:148)
    at com.fasterxml.jackson.databind.DeserializationContext.wrongTokenException(DeserializationContext.java:946)
    at com.fasterxml.jackson.databind.jsontype.impl.AsWrapperTypeDeserializer._deserialize(AsWrapperTypeDeserializer.java:91)
    at com.fasterxml.jackson.databind.jsontype.impl.AsWrapperTypeDeserializer.deserializeTypedFromObject(AsWrapperTypeDeserializer.java:49)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeWithType(BeanDeserializerBase.java:992)
    at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:247)
    at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:217)
    at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:25)
    at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:520)
    at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:101)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:258)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:125)
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3736)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2620)
    at test.RunThis.readJacksonFile(RunThis.java:84)
    at test.RunThis.main(RunThis.java:137)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

Maybe I am just doing something stupid but it seems like Jackson should be able to read a file that it generated.

@cowtowncoder
Copy link
Member

@rpatrick00 General idea is indeed that Jackson should read content it writes, at minimum.

What would be necessary here however is definition of Java classes, and code invoked, ideally simplified as much as possible to reproduce the problem.

@rpatrick00
Copy link
Author

@cowtowncoder, the github project I pointed you to is a VERY simple reproducer that has been stripped down to the essentials needed to reproduce the problem. There was no way for me to attach the project to the issue so I just pointed you at it. Is there a better way to do this?

@cowtowncoder
Copy link
Member

@rpatrick00 Sorry, my bad. Read this too quickly and missed the link. Thank you for providing the repro project.

@cowtowncoder cowtowncoder transferred this issue from FasterXML/jackson-databind Sep 12, 2019
@cowtowncoder
Copy link
Member

I was able to reproduce the issue against Jackson 2.6.3, but not with 2.6.7 or later. Looking at release notes, perhaps this was fixed by #177.

So I think this has been fixed now.

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