jaxb Unmarshaller : repeated xmlelement without wrapper

jackson, jaxb

Solution

If you want to use "unwrapped" representation, you need to use Jackson 2.1, and indicate unwrapped option:

@JacksonXmlElementWrapper(useWrapping=false)

alternatively, if using JAXB annotations, default should be not to use wrapping.

Finally, you can also change the default not to use wrapper element, with:

JacksonXmlModule module = new JacksonXmlModule();
// to default to using "unwrapped" Lists:
module.setDefaultUseWrapper(false);
XmlMapper xmlMapper = new XmlMapper(module);

Problem

``` <a> <b1>b1</b1> <b2>b2</b2> <b3> <c1></c1> <c2></c2> </b3> <b3> <c1></c1> <c2></c2> </b3> <b3> <c1></c1> <c2></c2> </b3> </a> ``` Since all the `<b3>` are not included in a wrapper element, say `<b3s>` when I use Jackson `XmlMapper` to read the XML file to my POJO Java Bean class, I got exception ``` com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value of type [simple type, class com.xxxxx] from String value; no single-String constructor/factory method (through reference chain: com.xxxx["xxx"]->com.xxx["xxx"]) ``` What annotation shall I use? ``` @XmlElement public List<B3> b3; ```

Original source