Can not deserialize unwrapped list when `@JacksonXmlProperty` localName matches `@JacksonXmlRootElement` localName
See original GitHub issuePlease refer to http://stackoverflow.com/questions/20673153/using-jackson-to-deserialize-a-collection-of-children-with-the-same-type-as-the
I can not figure out how to deserialize a document like this:
<test id="0">
<test id="0.1">
<test id="0.1.1" />
</test>
<test id="0.2" />
<test id="0.3">
<test id="0.3.1" />
</test>
</test>
Where each test
element is deserialized into a simple POJO.
Here is the code I am dealing with.
public class UnitTest {
@Test
public void test() throws Exception {
final ObjectMapper mapper = new XmlMapper();
final XmlTest before =
new XmlTest("0", Lists.newArrayList(new XmlTest("0.1", null),
new XmlTest("0.2", Lists.newArrayList(new XmlTest("0.2.1", null)))));
final String xml = mapper.writeValueAsString(before);
System.out.println(xml);
final XmlTest after = mapper.readValue(xml, XmlTest.class);
}
@JacksonXmlRootElement(localName = "test")
public static class XmlTest {
@JacksonXmlProperty(localName = "id", isAttribute = true)
private String id;
@JacksonXmlElementWrapper(useWrapping = false)
@JacksonXmlProperty(localName = "test")
private List<XmlTest> children;
public XmlTest() {}
public XmlTest(final String id, final List<XmlTest> children) {
this.id = id;
this.children = children;
}
}
}
My imported dependencies:
compile group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-xml', version: jacksonVersion
compile group: 'com.fasterxml.jackson.jaxrs', name: 'jackson-jaxrs-xml-provider', version: jacksonVersion
jacksonVersion=2.2.+
Issue Analytics
- State:
- Created 10 years ago
- Reactions:2
- Comments:9 (4 by maintainers)
Top Results From Across the Web
java - Can not deserialize unwrapped list when ...
I have found that changing the name of the root element in the XML document will result in successful deserialization. This is interesting ......
Read more >Issue with order of inheritance type attribute - Google Groups
The deserialization fails when the type attribute is not the first attribute in the ... @JacksonXmlProperty(localName = ATTRIBUTE_TYPE, isAttribute = true)
Read more >Solving the XML Problem with Jackson - Stackify
This can only adjust the Namespace and Local name – since the root element can never be serialized as an attribute. For example,...
Read more >Jackson 2.12: improved XML module - cowtowncoder - Medium
Nested Lists in POJOs should work reliably (esp. unwrapped) ... to have edge cases for deserialization (serialization did not have issues); ...
Read more >[Solved]-Getting Thumbnails from Google books api-Java
I find these nested Json files/strings are confusing, but I did get the above to work by reading another post here. Here is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Initially was planning to fix for 2.12 only, but as per user request, backport in 2.11 for 2.11.1.
I fixed #393, which is probably related, but unfortunately that did not yet resolve this issue. Hoping to have a look to see if I can fix it.