Failed to parse List of elements with attributes
fasterxml, jackson, java, xml
Solution
I could get the result after some changes. However, it could get first row out (it is null). And I don't know why.
@JacksonXmlElementWrapper(useWrapping=false)
@JacksonXmlProperty(localName="link")
private Collection<Link> links;
Updated: This should be a bug in version 2.1.4. I just tried master, this works fine.
Problem
I have object Links that has a member of List while Link has only attributes but parsing of the list has something wrong - it is created empty. In the test below `links.getLinks()` returns empty list. Any ideas? XML example: ``` <links> <link x="1" y="2" /> <link x="3" y="4" /> </links> ``` The Java ``` @JacksonXmlRootElement(localName="links") public class Links extends BaseAmebaElement { @JacksonXmlProperty(localName="link") //@JacksonXmlElementWrapper(localName="link") private Collection<Link> links; public Collection<Link> getLinks() { return links; } public void setLinks(Collection<Link> links) { this.links = links; } } ``` ... ``` @JacksonXmlRootElement(localName="link") public class Link { @JacksonXmlProperty(localName="x", isAttribute=true) private String href; @JacksonXmlProperty(localName="y", isAttribute=true) private String rel; ``` ... ``` XmlMapper xmlMapper = new XmlMapper (); try { Links links = xmlMapper.readValue(input, Links.class); assertNotNull(links); assertNotNull(links.getLinks()); assertEquals(2, links.getLinks().size()); } catch (Throwable e) { fail(e.getMessage()); } ```