Skip to content

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

@sandboxcoder

Description

@sandboxcoder

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!

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