【问题标题】:JAXB Unmarshalling not unmarshalling nested listJAXB 解组不解组嵌套列表
【发布时间】:2016-04-28 21:28:10
【问题描述】:

我在 JAXB 解组中遇到了一个新问题

给定这个字符串作为输入

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

该类不解析嵌套列表元素,只解析普通属性(表示为JSON):

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

这里有什么问题?我的课程是:

@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;
}

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")
}

我的解组非常标准:

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();

所以我不知道问题可能是什么。关于我做错了什么有什么想法吗?

【问题讨论】:

    标签: java xml jaxb


    【解决方案1】:

    在 Java 8 中运行代码解决了这个问题。如果有人想澄清为什么 Marshaller 会受到影响,我很想知道答案

    【讨论】:

      猜你喜欢
      • 2014-10-31
      • 1970-01-01
      • 2021-10-20
      • 1970-01-01
      • 2017-02-08
      • 1970-01-01
      • 1970-01-01
      • 2011-01-15
      • 2014-02-25
      相关资源
      最近更新 更多