Skip to content

Two wrapped lists with items of same name conflict #192

@TeemuStenhammar

Description

@TeemuStenhammar

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.2name-collisionIssue related to name collision wrt element/attr or nested lists

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions