我已经看过一些与此相关的讨论,但不能在以下场景中应用此方法。我正在尝试unmarshall an xml using jaxb
。
以下是我所有课程的层次结构。
@XmlRootElement(name="entry")
class Entry extedns Base{
@XmlElement
private String id;
@XmlElement
private String name;
@XmlElementRef
@XmlMixed
private Begin begin;
@XmlElementRef
@XmlMixed
private End end;
@XmlElementRef
private List<Link> links;
//Getter setters
}
@XmlRootElement(name="begin",namespace = "something")
public class Begin extends AnotherBase{
@XmlValue
private Float mFloat;
//Getter Setters
}
@XmlRootElement(name="end",namespace = "something")
public class End extends AnotherBase{
@XmlValue
private Float mFloat;
//Getter Setters
}
@XmlRootElement(name="link",namespace = "something")
public class Link extends Base{
private String attname;
private String attValue;
//Getter Setters
}
我想要一个像下面这样的xml:
<entry>
<id>...</id>
<name>...</name>
<begin>1.23344</begin>
<end>5.0</end>
<link>
<link>......</link>
<link>......</link>
</link>
</entry>
尽你所能,
Entry类包含2个@XmlElement
带注释的变量和2个@XmlElementRef
带注释的变量(Begin,End)。
Begin和End类都有@Xmlvalue
注释变量。
Begin和End类都来自其他类
Link类可能包含属性和元素类型的变量。
我没有使用@XmlMixed
,因为您可以看到我将@XmlMixed
放在Entry类的变量声明的顶部。
此编组的结果是
@XmlValue is not allowed on a class that derives another class.
this problem is related to the following location:
at private java.lang.Float Begin.mFloat
at Begin
at private Begin Entry.begin
If a class has @XmlElement property, it cannot have @XmlValue property.
this problem is related to the following location:
at private java.lang.Float Begin.mFloat
at Begin
答案 0 :(得分:1)
您可以使用AnotherBase
注释@XmlTransient
,将其作为映射的超类删除。如果AnotherBase
上有任何未使用@XmlAttribute
映射的获取/设置方法对,则需要使用@XmlTransient
对其进行注释。
@XmlMixed
和begin
属性不需要end
注释。
我注意到你正在注释字段(实例变量)。执行此操作时,应在类@XmlAccessorType(XmlAccessType.FIELD)上指定以下内容`