我有以下的对象层次结构,我需要从XML解组:
A:
String id;
List<B>
B:
String id;
List<C>
C:
String id;
我需要使用JAXB将它们解组为一个看起来像这样的xml(对象包含在一般的O对象中):
<O>
<A id="someId">
<B id="someId2">
<C id="someId3">
</B>
<B id="someId4">
<C id="someId5"/>
<C id="someId6"/>
</B>
</A>
</O>
我试图通过创建“GeneralType”类型的对象来实现这一点:
@XmlTransient
public abstract GeneralType:
protected String id
protected List<? extends GeneralType> myList
public O:
List<A> aList;
getter to aList with (@xmlElement(name="A"))
@XmlRootElement(name="A")
public A extends GeneralType:
getId with @XmlAttribute(name="id")
getMyListwith @XmlAttribute(name="B")
@XmlRootElement(name="B")
public B extends GeneralType:
getId with @XmlAttribute(name="id")
getMyListwith @XmlAttribute(name="C")
@XmlRootElement(name="C")
public C extends GeneralType:
getId with @XmlAttribute(name="id")
我收到错误:
@XmlAttribute/@XmlValue need to reference a Java type that maps to text in XML.:
A.getMyList
O.getALit
我做错了什么?