我们从遗留系统获得了一些导出的数据,我们需要通过JAXB等将它作为对象导入Java。你知道如何为这种情况编写任何XmlAdapter吗? 非常感谢你!
<document>
<label1>Some text</label1>
<label2 multivalue="true">
<values count="1">
<value>Some other text</value>
</values>
</label2>
</document>
<document>
<label1 multivalue="true">
<values count="1">
<value>Some other text</value>
</values>
</label1>
<label2>Some text</label2>
</document>
到目前为止的进展:
@XmlRootElement(name = "document")
@XmlAccessorType(XmlAccessType.FIELD)
public class Document {
@XmlElement(name = "label1")
private LabelObject label1;
...
}
@XmlAccessorType(XmlAccessType.FIELD)
public class LabelObject {
@XmlElement(name="values")
private ValueObject valuesObject;
...
}
@XmlAccessorType(XmlAccessType.FIELD)
public class ValueObject {
@XmlElement(name = "value")
private List<String> valueList
...
}
然后尝试取消联合
Document doc = (Document) JAXBContext.newInstance(Document.class, LabelObject.class, ValueObject.class).createUnmarshaller().unmarshal(new File(xmlPath));
但它不起作用。它看起来似乎并非无足轻重: - )