Two wrapped lists with items of same name
See original GitHub issueHello!
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)?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:18
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to deal with the possibility of multiple list elements having ...
I typically extract list elements by name. Now I'm worried that I will accidentally create lists with multiple elements having the same name...
Read more >Each list element is wrapped into an extra tag with the name of ...
Each list element is wrapped into an extra tag with the name of the list property (RFE: combine type id, property name) #230....
Read more >flex-wrap - CSS: Cascading Style Sheets - MDN Web Docs
The flex-wrap property is specified as a single keyword chosen from the list of values below. Values. The following values are accepted: nowrap....
Read more >Built-in Functions — Python 3.11.1 documentation
This generates a string similar to that returned by repr() in Python 2. ... If the object is a module object, the list...
Read more >Effective Dart: Usage
Given an Iterable, there are two obvious ways to produce a new List that contains the same elements: var copy1 = iterable.
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
Would like to know what the suggested workaround is. Should I just always wrap list properties in a class that contains just the list?
@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.