我在JAXB unmarshalling中遇到了一个新问题
将此字符串作为输入
<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();
所以我不知道问题是什么。关于我做错了什么想法?
答案 0 :(得分:0)
在Java 8中运行代码解决了这个问题。如果有人想澄清为什么Marshaller会受到影响,我很想知道答案