Failed to parse List of items with attributes

I have a Links object that has a List member, while a link has only attributes, but the analysis of the list has something wrong - it is created empty.
In the test below links.getLinks() returns an empty list. Any ideas?
XML example:

 <links> <link x="1" y="2" /> <link x="3" y="4" /> </links> 

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()); } 
+4
source share
1 answer

I could get the result after some changes. However, it can get the first row (it is zero). And I do not 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 great.

+5
source

All Articles