jackson-dataformat-xml
jackson-dataformat-xml copied to clipboard
Two wrapped lists with items of same name
Hello!
Please, consider following test case:
/** Two lists */
public static final String TEST_TWO_LISTS =
" <Wrapper>" +
" <ones> " +
" <name>item0</name>" +
" <name>item1</name>" +
" </ones>" +
" <twos>" +
" <name>item2</name>" +
" <name>item3</name>" +
" </twos>" +
" </Wrapper>";
static class Wrapper {
@JacksonXmlElementWrapper(localName = "ones")
@JacksonXmlProperty(localName = "name")
public List<String> ones;
@JacksonXmlElementWrapper(localName = "twos")
@JacksonXmlProperty(localName = "name")
public List<String> twos;
}
@Test
public void shouldHandleNestedListsWithObjects() throws IOException {
ObjectMapper xmlMapper = new XmlMapper();
Wrapper wrapper = xmlMapper.readValue(TEST_TWO_LISTS, Wrapper.class);
assertNotNull(wrapper);
}
This test fails with error:
com.fasterxml.jackson.databind.JsonMappingException: Multiple fields representing property "name"
Is this a known is a known issue and may I handle this situation without need for two extra classes (Ones and Twos)?
@TeemuStenhammar Unfortunately this is a known problem. There should not be such collision, given that wrappers differ, but due to internal limitations (based on databind in JSON not using wrappers) this exists. I think there is at least one existing issue report (maybe #27). It is not clear as to what would be the easiest way to resolve this, which is why there is no solution yet.
@cowtowncoder Ok, I'll manage then with extra classes. Thank you for the reply.
However, I have another issue that is actually blocking my progress now totally. I am just creating an issue about that and would really appreciate any help in either fixing or circumventing it.
Should I close this issue now that it is duplicate?
@TeemuStenhammar let's leave this open for now; I can close this (or other issue(s)) depending on which has the best description.
Would like to know what the suggested workaround is. Should I just always wrap list properties in a class that contains just the list?
I come back one year later. :) Is a fix has been done for this issue ?