Skip to content
This repository was archived by the owner on Jan 22, 2019. It is now read-only.
This repository was archived by the owner on Jan 22, 2019. It is now read-only.

Jackson can't handle @XmlElements and @XmlElementWrapper correctly #34

@splatch

Description

@splatch

Code written below works perfectly with plain JAXB but causes issues with Jackson. I found no way to handle similar structure by Fasterxml - wrapper + child elements having various names.

@XmlRootElement(name = "foo")
@XmlAccessorType(XmlAccessType.FIELD)
public class XmlFail {

    @XmlElementWrapper(name = "items")
    @XmlElements({
        @XmlElement(name = "double", type = Double.class),
        @XmlElement(name = "integer", type = Integer.class)
    })
    private List<Number> items;

    public static void main(String[] args) throws Exception {
        JAXBContext context = JAXBContext.newInstance(XmlFail.class);

        String xml = 
        "<foo>" +
            "<items>" +
                "<double>2.0</double>" +
                "<integer>1</integer>" +
            "</items>" +
        "</foo>";

        XmlFail unmarshal = (XmlFail) context.createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes()));
        System.out.println(unmarshal.getClass() + " " + unmarshal.items);
    }

}```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions