I have a very simple example of a class with a List member that uses polymorphism. The Java code looks like this:
@XmlRootElement(name = "company")
@XmlAccessorType(XmlAccessType.FIELD)
public class Company {
@XmlElements({
@XmlElement(type = DesktopComputer.class, name = "desktop"),
@XmlElement(type = LaptopComputer.class, name = "laptop")
})
private List computers;
...
}
JAXB serializes the output correctly (or at least in the way that I want it) like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<company>
<computers>
<desktop id="computer-1">
<location>Bangkok</location>
</desktop>
<desktop id="computer-2">
<location>Pattaya</location>
</desktop>
<laptop id="computer-3">
<vendor>Apple</vendor>
</laptop>
</computers>
</company>
Jackson JAXB annotations wraps each resulting element in the list in a redundant <computers> tag like this:
<?xml version='1.1' encoding='UTF-8'?><company><computers>
<computers>
<desktop id="computer-1">
<location>Bangkok</location>
</desktop>
</computers>
<computers>
<desktop id="computer-2">
<location>Pattaya</location>
</desktop>
</computers>
<computers>
<laptop id="computer-3">
<vendor>Apple</vendor>
</laptop>
</computers>
</computers>
</company>
How can I eliminate the extra wrapping Jackson is doing to generate the same shape as JAXB?