简体   繁体   中英

JAXB Unmarshalling not unmarshalling nested list

I've been coming across a new issue in my JAXB unmarshalling

Given this string as an input

<ruleGroup id="1602" name="TestObject">
    <simple column="simple" type="value" operator="equals" value="1" not="true"/>
</ruleGroup>

The class does not parse the nested list element, only normal attributes (represented as a JSON):

{"id":1602,"name":"TestObject"}

What is the issue here? My classes are:

@XmlRootElement(name = "ruleGroup")
public class RuleGroup {

    @XmlAttribute(name = "id")
    public Long id;
    @XmlAttribute(name = "name")
    public String name;

    @XmlElement(name = "simple")
    public List<SimpleXML> simple;
}

and

public class SimpleXML {
    @XmlAttribute(name = "column")
    public String column = null;
    @XmlAttribute(name = "type")
    public String type = null;
    @XmlAttribute(name = "operator")
    public String operator = null;
    @XmlAttribute(name = "value")
    public String value = null;
    @XmlAttribute(name = "not")
}

My unmarshalling is pretty standard:

RuleGroup rule;
JAXBContext jaxbContext = JAXBContext.newInstance(RuleGroup.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
StringReader reader = new StringReader(test);
JAXBElement<RuleGroup> root = jaxbUnmarshaller.unmarshal(new StreamSource(reader), RuleGroup.class);
rule = (RuleGroup) root.getValue();

So I don't know what the issue could be. Any ideas on what I'm doing wrong?

Running the code in Java 8 resolved the issue. If anyone wants to clarify why the Marshaller is affected by that I'd love to know the answer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM