Jaxb 将XmlIDREF/XmlID与接口和泛化一起使用时,EclipseLink错误50035
我正在尝试Jaxb 将XmlIDREF/XmlID与接口和泛化一起使用时,EclipseLink错误50035,jaxb,eclipselink,moxy,Jaxb,Eclipselink,Moxy,我正在尝试@XmlIDREF参考方法。注释为: /** *属性/列表属性的getter *@返回属性 */ @XmlElementWrapper(name=“attributes”) @XmlElements({ @XmlElement(name=“Attribute”,type=AttributeJaxbDao.class) }) @XmlIDREF 公共列表getAttributes(){ 这将导致错误消息: javax.xml.bind.JAXBException: Exception
@XmlIDREF
参考方法。注释为:
/**
*属性/列表属性的getter
*@返回属性
*/
@XmlElementWrapper(name=“attributes”)
@XmlElements({
@XmlElement(name=“Attribute”,type=AttributeJaxbDao.class)
})
@XmlIDREF
公共列表getAttributes(){
这将导致错误消息:
javax.xml.bind.JAXBException:
Exception Description: Since the property or field [attributes] is set as XmlIDREF, the target type of each XmlElement declared within the XmlElements list must have an XmlID property. Please ensure the target type of XmlElement [Attribute] contains an XmlID property.
- with linked exception:
[Exception [EclipseLink-50035] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.JAXBException
Exception Description: Since the property or field [attributes] is set as XmlIDREF, the target type of each XmlElement declared within the XmlElements list must have an XmlID property. Please ensure the target type of XmlElement [Attribute] contains an XmlID property.]
at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(JAXBContext.java:832)
at org.eclipse.persistence.jaxb.JAXBContext.<init>(JAXBContext.java:143)
“标准使用”有两个不同之处:
@xmlement
注释中,该类型被专门命名为AttributeJaxbDao.class是否有解决办法。我希望避免被迫不使用界面和概括。注意:我是专家组的负责人和成员 不幸的是,我们有两个bug阻止这个用例正常工作
完整示例 下面是一个比你问题中给出的模型稍微复杂一点的模型,我将用它来证明现在一切正常 Foo
Foo
类有两个类型为List
的属性,Attribute
是一个接口。这两个属性都用@XmlElements
注释,其中包含指定具体类型的@XmlElement
注释。attributeRefs
属性也用@XmlIDREF
注释
import java.util.*;
导入javax.xml.bind.annotation.*;
@XmlRootElement
公开课Foo{
@XmlElementWrapper(name=“Attributes”)
@XmlElements({
@XmlElement(name=“attributefo”,type=AttributeJaxbDao.class),
@xmlement(name=“AttributeBar”,type=AttributeJaxbDao2.class)
})
列表属性=新建ArrayList();;
@XmlElementWrapper(name=“AttributeRefs”)
@XmlElements({
@XmlElement(name=“attributerefoo”,type=AttributeJaxbDao.class),
@XmlElement(name=“AttributeRefBar”,type=AttributeJaxbDao2.class)
})
@XmlIDREF
List attributeRefs=new ArrayList();
}
属性
属性
只是一个非常简单的界面
公共接口属性{
}
这是属性
的一个实现,它包含一个用@XmlID
注释的字段,该字段将被@XmlIDREF
注释利用
import javax.xml.bind.annotation.*;
@XmlAccessorType(XmlAccessType.FIELD)
公共类AttributeJaxbDao实现属性{
@xmltattribute(name=“id”)
@XmlID
字符串id;
字符串名;
}
属性2
这也是属性
的一个实现,该属性有一个用@XmlID
注释的字段
import javax.xml.bind.annotation.*;
@XmlAccessorType(XmlAccessType.FIELD)
公共类AttributeJaxbDao2实现属性{
@xmltattribute(name=“id”)
@XmlID
字符串id;
字符串名;
}
演示
下面是一些演示代码,您可以运行这些代码来证明一切正常:
导入java.io.File;
导入javax.xml.bind.*;
公开课演示{
公共静态void main(字符串[]args)引发异常{
JAXBContext jc=JAXBContext.newInstance(Foo.class);
Unmarshaller Unmarshaller=jc.createUnmarshaller();
File xml=新文件(“src/forum14921547/input.xml”);
Foo Foo=(Foo)unmarshaller.unmarshal(xml);
Marshaller=jc.createMarshaller();
setProperty(marshaller.JAXB_格式化的_输出,true);
marshaller.marshall(foo,System.out);
}
}
input.xml/Output
A.
B
C
A.
B
C
作为一种解决方法,您可以创建impl类型的属性。此外,我们应该能够在明天签入一个修复程序,该程序将在周三上午在2.4.2夜间版本中提供。Blaise-我不能列出与Java中的列表不兼容…请阅读我个人关于我正在寻找的功能组合的消息:泛型,在介面、继承、ref/id处理感谢您对此进行了深入的研究和所有的努力。问题仍然存在:异常描述:由于属性或字段[attributes]设置为XmlIDREF,因此XmlElements列表中声明的每个XmlElement的目标类型必须具有XmlID属性。请确保XmlElement的目标类型为[Attribute]包含一个XmlID属性。-带有链接的异常:[exception[EclipseLink-50035](Eclipse持久性服务-2.4.2.v20130315-93567e3):org.Eclipse.Persistence.exceptions.jaxbeException我假设这是因为您的示例中的继承是相反的。我必须注释掉这个://@xmlseealas({AttributeJaxbDao.class})在AttributeJaxBao的基类中…非常strange@WolfgangFahl-你能为你看到的问题打开一个bug吗()?如果你能给它附加示例代码来演示这个问题,这将帮助我们更快地完成修复。