环境:带有 EclipseLink MOXy 的 JAXB 2.1.2
要求:
我想在编组时得到这样的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<root id="id123">
<email>test@gmail.com</email>
<address type="short">...</address>
</root>
我用这两个类对此进行建模:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name="root")
public class ClassA {
@XmlAttribute(name="id")
private String id = null;
@XmlElement(name="address")
private Address addr = new Address();
// and some getters setters
}
和
@XmlAccessorType(XmlAccessType.FIELD)
public class Address {
@XmlElement(name="address")
private String address = null;
@XmlAttribute(name="type")
private String type = null;
}
我得到的是这个,地址被嵌套两次:
<?xml version="1.0" encoding="UTF-8"?>
<root id="id123">
<email>test@gmail.com</email>
<address type="short">
<address>...</address>
</address>
</root>
如何删除一个层次结构?