WebService客户端和列表<;JAXBElement<&燃气轮机&燃气轮机;

WebService客户端和列表<;JAXBElement<&燃气轮机&燃气轮机;,jaxb,cxf,webservice-client,Jaxb,Cxf,Webservice Client,例如,当我尝试从wsdl文档生成客户机时,我得到的客户机似乎有很多JAXBElement属性 protected List<JAXBElement<?>> nameOrLinkingNameOrFamilyName; protectedlistAJAXBElement将为choice属性生成,其中多个XML元素将对应于同一个Java类。这是为了保留有关元素的信息,因为这不能从值的类型派生 binding.xml 以下JAXB模式绑定文件将确保生成choice属性: &l

例如,当我尝试从wsdl文档生成客户机时,我得到的客户机似乎有很多JAXBElement属性

protected List<JAXBElement<?>> nameOrLinkingNameOrFamilyName;

protectedlistA
JAXBElement
将为choice属性生成,其中多个XML元素将对应于同一个Java类。这是为了保留有关元素的信息,因为这不能从值的类型派生

binding.xml

以下JAXB模式绑定文件将确保生成choice属性:

<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
          version="2.1">
    <globalBindings choiceContentProperty="true"/>
</bindings> 
由于choice属性的值足以唯一标识元素,因此该属性不包含用于保留此信息的JAXBElement:

@XmlElements({
    @XmlElement(name = "address", type = Address.class),
    @XmlElement(name = "phone-number", type = PhoneNumber.class),
    @XmlElement(name = "note", type = String.class)
})
protected Object addressOrPhoneNumberOrNote;
@XmlElementRefs({
    @XmlElementRef(name = "phone-number", type = JAXBElement.class),
    @XmlElementRef(name = "email", type = JAXBElement.class),
    @XmlElementRef(name = "address", type = JAXBElement.class),
    @XmlElementRef(name = "note", type = JAXBElement.class)
})
protected JAXBElement<?> addressOrPhoneNumberOrNote;

将生成
JAXBElement
属性的XML模式

现在我们将修改choice结构,使
note
email
方法都对应于
String

<xsd:choice>
    <xsd:element name="address" type="address"/>
    <xsd:element name="phone-number" type="phoneNumber"/>
    <xsd:element name="note" type="xsd:string"/>
    <xsd:element name="email" type="xsd:string"/>
</xsd:choice>

由于choice属性的值不再足以唯一标识元素,因此该属性必须包含JAXBElement以保留此信息:

@XmlElements({
    @XmlElement(name = "address", type = Address.class),
    @XmlElement(name = "phone-number", type = PhoneNumber.class),
    @XmlElement(name = "note", type = String.class)
})
protected Object addressOrPhoneNumberOrNote;
@XmlElementRefs({
    @XmlElementRef(name = "phone-number", type = JAXBElement.class),
    @XmlElementRef(name = "email", type = JAXBElement.class),
    @XmlElementRef(name = "address", type = JAXBElement.class),
    @XmlElementRef(name = "note", type = JAXBElement.class)
})
protected JAXBElement<?> addressOrPhoneNumberOrNote;
@xmlementrefs({
@xmlementref(name=“phone number”,type=JAXBElement.class),
@xmlementref(name=“email”,type=JAXBElement.class),
@xmlementref(name=“address”,type=JAXBElement.class),
@xmlementref(name=“note”,type=JAXBElement.class)
})
受保护的JAXBElement addressOrPhoneNumberOrNote;

了解更多信息


谢谢你的回答,所以你告诉我,如果我有对应于同一Java类的元素,那么我总是会得到一个JAXBElement?@Nicolas-这是真的,并确保您的XML文档可以往返。如果没有JAXB元素,您将如何区分哪个元素应该用于封送(即,在我的示例中,您会将String的实例包装在“email”或“note”中?