简体   繁体   English

JAXB生成List <Jaxbelement>而不是字段

[英]JAXB generates List<Jaxbelement> instead of fields

I'm trying to generate a class with the jaxb maven plugin from the following wsdl: 我正在尝试使用以下wsdl中的jaxb maven插件生成一个类:

<xs:complexType name="ctpLeerling">
<xs:sequence>
  <xs:element minOccurs="0" name="achternaam" type="xs:string"/>
  <xs:element minOccurs="0" name="voorvoegsel" type="xs:string"/>
  <xs:element minOccurs="0" name="voorletters-1" type="xs:string"/>
  <xs:element minOccurs="0" name="roepnaam" type="xs:string"/>
  <xs:element minOccurs="0" name="roepnaam" type="xs:string"/>
  <xs:element name="geboortedatum" type="xs:date"/>
  <xs:element minOccurs="0" name="geslacht" type="xs:string"/>
  <xs:element name="jaargroep" type="tns:ctpVocabulaireGebondenVeld"/>
  <xs:element minOccurs="0" name="emailadres" type="xs:string"/>
  <xs:element minOccurs="0" name="fotourl" type="xs:string"/>
  <xs:element minOccurs="0" name="groep">
    <xs:complexType>
      <xs:sequence/>
      <xs:attribute name="key" type="xs:string"/>
    </xs:complexType>
  </xs:element>
  <xs:element minOccurs="0" name="subgroepen">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" name="groep">
          <xs:complexType>
            <xs:sequence/>
            <xs:attribute name="key" type="xs:string"/>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element minOccurs="0" name="mutatiedatum" type="xs:dateTime"/>
</xs:sequence>
<xs:attribute name="key" type="xs:string" use="required"/>

It gives me a class that has the following fields: 它给了我一个具有以下字段的类:

protected List<JAXBElement<?>> content;
@XmlAttribute(name = "key", required = true)
protected String key;

How can I generate fields of the wsdl properties instead of a list with JAXBElements? 如何生成wsdl属性的字段而不是使用JAXBElements的列表? Thanks in advance! 提前致谢!

Edit: I'm sorry I forgot to mention that I cannot edit the wsdl file! 编辑:对不起,我忘了提到我无法编辑wsdl文件!

You are getting a List<JAXBElement> because you have two elements defined in your sequence with the same name. 您将获得List<JAXBElement>因为您的sequence定义了两个具有相同名称的元素。

<xs:element minOccurs="0" name="roepnaam" type="xs:string"/>
<xs:element minOccurs="0" name="roepnaam" type="xs:string"/>

The element would have been better defined as: 该元素可以更好地定义为:

<xs:element minOccurs="0" maxOccurs="2" name="roepnaam" type="xs:string"/>

If you can't find a way to generate the class you want, you can always create one yourself and use an external binding file to have JAXB use if for that complex type during class generation. 如果找不到生成所需类的方法,则可以自己创建一个并使用外部绑定文件在类生成期间使用JAXB(如果是复杂类型)。

<jxb:bindings schemaLocation="yourSchema.xsd">
    <jxb:bindings node="//xs:complexType[@name='ctpLeerling']">
        <jxb:class ref="com.example.YourOwnClass"/>
    </jxb:bindings>
</jxb:bindings>

You can customize the generation with an external bindings file. 您可以使用外部绑定文件自定义生成。

You can go through an example here . 你可以在这里看一个例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM