问题
using JAXB 2.2.5b, and having
@XmlSeeAlso({BeanView.class, ViewField.class, ViewPanel.class, ViewTab.class, ElementRef.class})
@XmlRootElement
public abstract class ViewElement {
@XmlID
@XmlAttribute
public String getId() {
return id;
}
}
@XmlRootElement(name="ref")
public class ElementRef extends ViewElement{
private ViewElement target;
@XmlElement
@XmlIDREF
public ViewElement getTarget() {
return target;
}
public void setTarget(ViewElement target) {
this.target = target;
}
}
Many class extends the abstract ViewElement
@XmlRootElement
public class ViewField extends ViewElement{
}
@XmlRootElement
public class ViewPanel extends ViewElement{
}
in the XML the ElementRef target element is repeated instead of keeping only the id ref
<ref id="mvmCredit" >
<target xsi:type="viewField" valueExpr="" row="0" ... all ViewField attributes >
</target>
</ref>
and during the unmarchaling of the XML model the target is null (the restoration failed)
回答1:
An upgrade to JAXB 2.2.7 fix the problem
来源:https://stackoverflow.com/questions/24823594/xmlidref-is-not-working