Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unwrapped list ignore attributes if 2 lists in sequence #108

Closed
pgelinas opened this issue Mar 13, 2014 · 4 comments
Closed

Unwrapped list ignore attributes if 2 lists in sequence #108

pgelinas opened this issue Mar 13, 2014 · 4 comments
Milestone

Comments

@pgelinas
Copy link
Member

If there is two unwrapped list in sequence in the input xml, the first element of the second list gets its attributes ignored.

Here's a sample input:

<Foo><firstBar id="1"><value>FIRST</value></firstBar>
<secondBar id="2"><value>SECOND</value></secondBar></Foo>

Here's a unit test:

@RunWith(JUnit4.class)
public class TestXmlBug {

    static class Foo {
        @JacksonXmlElementWrapper(useWrapping = false)
        public List<Bar> firstBar = new ArrayList<Bar>();
        @JacksonXmlElementWrapper(useWrapping = false)
        public List<Bar> secondBar = new ArrayList<Bar>();
    }

    static class Bar {
        public String value;

        @JacksonXmlProperty(isAttribute = true)
        public int id;
    }

    @Test
    public void testName() throws Exception {
        XmlMapper xmlMapper = new XmlMapper();
        Foo foo = new Foo();
        Bar bar1 = new Bar();
        bar1.id = 1;
        bar1.value = "FIRST";
        foo.firstBar.add(bar1);
        Bar bar2 = new Bar();
        bar2.value = "SECOND";
        bar2.id = 2;
        foo.secondBar.add(bar2);
        String string = xmlMapper.writeValueAsString(foo);
        Foo fooRead = xmlMapper.readValue(string, Foo.class);
        assertEquals(foo.secondBar.get(0).id, fooRead.secondBar.get(0).id);
    }
}

I would have made a regular PR for the unit test but I'm not in my usual workspace and don't have Jackson setup just now.

@cowtowncoder
Copy link
Member

Thanks; I can merge in the test case no problem.

@cowtowncoder
Copy link
Member

Added this as failing test AttributeFailIssue108Test.

cowtowncoder added a commit that referenced this issue Mar 21, 2014
@cowtowncoder cowtowncoder added this to the 2.4.0 milestone Apr 5, 2014
@cowtowncoder
Copy link
Member

Works now, not sure which fix did it, guessing it could be #101.

@pgelinas
Copy link
Member Author

pgelinas commented Apr 7, 2014

Sounds like a reasonable guess!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants