Java JAXB与复合模式
我现在正在与JAXB合作,我正在努力注释我的预处理查询的复合概念,以便JAXB感到高兴 前提条件查询可以是:Java JAXB与复合模式,java,xml,jaxb,composite,Java,Xml,Jaxb,Composite,我现在正在与JAXB合作,我正在努力注释我的预处理查询的复合概念,以便JAXB感到高兴 前提条件查询可以是: 简单:仅包含查询的文本节点 复合物 或:1个前提条件查询的前提条件或其他匹配项 AND:1个前提条件查询的前提条件和其他匹配项 当然,复合查询可以由复合查询组成,如下例所示: <precondition> <or> <and> <query>foo<
- 简单:仅包含查询的文本节点
- 复合物
- 或:1个前提条件查询的前提条件或其他匹配项
- AND:1个前提条件查询的前提条件和其他匹配项
<precondition>
<or>
<and>
<query>foo</query>
<query>bar</query>
</and>
<query>baz</query>
</or>
</precondition>
对于复合查询(CompoundOrPreconditionQuery基本相同):
最后,JAXB抱怨无法解决这一问题:
Caused by: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Invalid @XmlElementRef : Type "class xxx.PreconditionQuery" or any of its subclasses are not known to this context.
this problem is related to the following location:
at public xxx.PreconditionQuery xxx.Precondition.getQuery()
at xxx.Precondition
如果@xmlementref
不执行此任务,将执行什么操作?请尝试添加
@XmlSeeAlso({PreconditionQuery.class})
到您的compoundandpremissionquery
类
然后,尝试用@XmlRootElement
注释所有的预处理查询
类/子类
另外,在使用@xmlacessortype
时要小心一点——有时你有,有时没有。最好用它来注释包
最后,您可能需要一个带有@XmlRegistry
和@xmlementdecl
的ObjectFactory
,但我认为这不是绝对必需的
我认为问题在于缺少@XmlRootElement
/@xmlseea
注释
@xmlementref
众所周知是个棘手的问题,但它确实有效。:)
祝您好运,并致以最良好的祝愿。谢谢,我很快会尝试一下。我更新了初始代码示例以匹配您的建议。现在,JAXB不再抱怨了,但是
查询总是空的,现在的问题似乎与以下事实有关:SimplePreconditionQuery
包装了XmlValue
,而不是像其他实现那样包装了XmlElement
。我希望避免改变XML结构,但是…@Rolf请问另一个问题演示新的映射/类等。大问题往往具有“请咨询我”的天赋,对其他人没有太大帮助。小问题产生的结果可以在社区中重复使用。
public class Precondition {
private PreconditionQuery query;
@XmlElementRef(required = true)
public PreconditionQuery getQuery() {
return query;
}
public void setQuery(PreconditionQuery query) {
this.query = query;
}
}
Caused by: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Invalid @XmlElementRef : Type "class xxx.PreconditionQuery" or any of its subclasses are not known to this context.
this problem is related to the following location:
at public xxx.PreconditionQuery xxx.Precondition.getQuery()
at xxx.Precondition
@XmlSeeAlso({PreconditionQuery.class})