我需要包含类字段的marshal类,但不包含类根标记。例如,我有类Person和Address:
@XmlRootElement(name="address")
class Address {
...
@XmlElement
String street;
}
@XmlRootElement(name="person")
class Person {
...
@XmlElement
Address address;
}
如果我整理它,我会得到:
<person>
...
<address>
<street>...<street>
<address>
</person>
但我需要:
<person>
...
<street>...<street>
</person>
答案 0 :(得分:0)
可能的解决方案可能是..
@XmlRootElement(name="address")
class Address {
...
@XmlElement
String street;
}
@XmlRootElement(name="person")
class Person {
...
@XmlTransient
Address address;
@XmlElement
public String getStreet() {
return (address!= null) ? address.getStreet() : null;
}
}