JAXB XmlID和XmlIDREF注释(Schema to Java) [英] JAXB XmlID and XmlIDREF annotations (Schema to Java)

查看:175
本文介绍了JAXB XmlID和XmlIDREF注释(Schema to Java)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CXF公开Web服务。我正在使用@XmlID和@XmlIDREF JAXB注释来在编组/解组期间维护对象图的参照完整性。

I am exposing a web service using CXF. I am using the @XmlID and @XmlIDREF JAXB annotations to maintain referential integrity of my object graph during marshalling/unmarshalling.

WSDL正确地包含具有xs:id的元素和xs:idref属性来表示这一点。

The WSDL rightly contains elements with the xs:id and xs:idref attributes to represent this.

在服务器端,一切都很好用。使用@XmlIDREF注释的类型实例与使用@XmlID注释注释的实例相同(<= p>)。

On the server side, everything works really nicely. Instances of Types annotated with @XmlIDREF are the same instances (as in ==) to those annotated with the @XmlID annotation.

但是,当我使用WSDLToJava生成客户端时,引用(使用@XmlIDREF注释的引用)的类型为java.lang.Object。

However, when I generate a client with WSDLToJava, the references (those annotated with @XmlIDREF) are of type java.lang.Object.

有没有办法可以自定义JAXB绑定,使得引用类型是java.lang.String(以匹配引用类型的ID)或者与引用类型本身相同?

Is there any way that I can customise the JAXB bindings such that the types of references are either java.lang.String (to match the ID of the referenced type) or the same as the referenced type itself?

推荐答案

好的,所以这不会起作用。 JAXB无法为IDREF生成具有正确类型的代码,因为架构无法指定引用类型,并且IDREF可能指向不同的复杂类型。 JAXB将如何知道引用的类型? XML Schema的扩展可以做到! :)

OK, so this isn't going to work. It's not possible for JAXB to generate code with the correct types for the IDREFs because the schema can't specify the types of references and there may be IDREF's pointing to different complex types. How would JAXB know what are the types of the references? An extension to XML Schema would do it! :)

这篇关于JAXB XmlID和XmlIDREF注释(Schema to Java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆