...
<items>
</items>
...@JacksonXmlProperty(localName = "item")
@JacksonXmlElementWrapper(localName = "items")
private List<Item> items;
Why I get the following deserialization error ?
Cannot deserialize instance of `java.util.ArrayList` out of VALUE_STRING token
I think that if we have this combination of annotations for a field then it should consider only collection items and nothing else inside the wrapping element. Is it bug or feature ?@JacksonXmlRootElement(localName = "test")
public class TestResult {
@JacksonXmlProperty(localName = "string")
@JacksonXmlElementWrapper(localName = "strings")
private List<String> strings;
public TestResult() {
}
public List<String> getStrings() {
return strings;
}
public void setStrings(List<String> strings) {
this.strings = strings;
}
}
void testElementWrapperWithNoElements() throws IOException {
ObjectMapper mapper = new XmlMapper();
String xml = "<test><strings></strings></test>";
TestResult res = mapper.readValue(xml, TestResult.class);
assert res != null && res.getStrings() == null;
}
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.ArrayList` out of VALUE_STRING token at [Source: (StringReader); line: 1, column: 16] (through reference chain: com.acme.TestResult["strings"]) at com.acme.XmlSerializationTest.testElementWrapperWithNoElements(XmlSerializationTest.java:258)