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

Can not deserialize unwrapped list when @JacksonXmlProperty localName matches the parent's localName #399

Closed
sandboxcoder opened this issue May 14, 2020 · 3 comments
Milestone

Comments

@sandboxcoder
Copy link

sandboxcoder commented May 14, 2020

Example code is here (requires Maven; simply run 'mvn test' to see the failure):
fullStackAngularSpringBoot.zip

Tested with latest 2.12.0-snapshot as of yesterday.

Below is the minimal xml it takes to expose the issue:

<main>
    <test>
        <test>
            <test>
            </test>
        </test>
    </test>
    <test>
    </test>
</main>

Where both main and test are very simple POJOs.

See Main.java:

import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

public class Main {
    @JacksonXmlProperty(localName = "test")
    @JacksonXmlElementWrapper(useWrapping = false)
    List<Test> list = new ArrayList<Test>();
}

Test.java:

import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

public class Test {
    @JacksonXmlProperty(localName = "test")
    @JacksonXmlElementWrapper(useWrapping = false)
    List<Test> list = new ArrayList<Test>();
}

Below is the exception:

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.kreationsedge.demo.DemoApplicationTests
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.294 s <<< FAILURE! - in com.kreationsedge.demo.DemoApplicationTests
[ERROR] contextLoads  Time elapsed: 0.292 s  <<< ERROR!
com.fasterxml.jackson.databind.JsonMappingException: Current state not XML_START_ELEMENT (1) but 2 (through reference chain: com.kreationsedge.demo.Main["test"]->java.util.ArrayList[0]->com.kreationsedge.demo.Test["test"]->java.util.ArrayList[0]->com.kreationsedge.demo.Test["test"]->java.util.ArrayList[0])
        at com.kreationsedge.demo.DemoApplicationTests.contextLoads(DemoApplicationTests.java:24)
Caused by: java.lang.IllegalStateException: Current state not XML_START_ELEMENT (1) but 2
        at com.kreationsedge.demo.DemoApplicationTests.contextLoads(DemoApplicationTests.java:24)

[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Errors: 
[ERROR]   DemoApplicationTests.contextLoads:24 » JsonMapping Current state not XML_START...
[INFO] 
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

This issue is related to the other bug but the reporter closed the issue after he found a workaround. I'll probably end up doing the same to resolve our issue but it would be ideal if we could get this fix ported into 2.11 if possible. Thanks!

@cowtowncoder
Copy link
Member

Interesting. This is not exactly the same as #86 as I actually added a fix for the problem case.
But looks like there may be an edge case that still results in similar problem, something getting out of sync. Input is bit different (the other case has attribute values, mapped to logical properties), which causes bit different token stream.

Thank you for reporting this case at any rate: it is important to tease out edge cases. Handling of unwrapped Lists is the major source of problems for this module.

@cowtowncoder cowtowncoder added this to the 2.10 milestone May 15, 2020
@cowtowncoder cowtowncoder removed the 2.12 label May 15, 2020
@cowtowncoder cowtowncoder modified the milestones: 2.10, 2.11.1 May 15, 2020
@cowtowncoder
Copy link
Member

Tricky. I think it's the empty List that was problem; code needs to avoid attempt to add virtual wrapping for those cases without failing. Fixed for 2.11(.1), 2.12.

@sandboxcoder
Copy link
Author

Thanks a lot I just tested in my project and verified the fix worked. Thank you very much for hopping on this so quickly!

I'll be looking out for 2.11.1's release!

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