question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Two wrapped lists with items of same name

See original GitHub issue

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)?

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:18
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
RikkiGibsoncommented, Jan 26, 2018

Would like to know what the suggested workaround is. Should I just always wrap list properties in a class that contains just the list?

2reactions
cowtowncodercommented, Apr 21, 2016

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found