Wsdl2Java 生成带有 protected List 的类<JAXBElement<?>> content

问题描述 投票:0回答:1

我们正在尝试与https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/taiif/wsdl/ixgd/DpiNtnlDeclaration_v1.0.wsdl

中发布的服务集成

我们已经使用插件“com.github.bjornvester.wsdl2java”配置了基于 gradle 的 springboot 应用程序

当工具从

生成地址类型的类时
    <xsd:complexType name="Address_Type">
        <xsd:sequence>
            <xsd:element name="CountryCode">
                <xsd:annotation>
                    <xsd:documentation>This data element provides the country code associated with the entity’s (or person’s) address.</xsd:documentation>
                </xsd:annotation>
                <xsd:simpleType>
                    <xsd:restriction base="iso:CountryCode_Type">
                        <xsd:minLength value="1"/>
                        <xsd:maxLength value="2"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:element>
            <xsd:choice>
                <xsd:element name="AddressFree" type="stf:StringMin1Max4000_Type">
                    
                </xsd:element>
                <xsd:sequence>
                    <xsd:element name="AddressFix" type="dpi:AddressFix_Type"/>
                    <xsd:element name="AddressFree" type="stf:StringMin1Max4000_Type" minOccurs="0">
                    </xsd:element>
                </xsd:sequence>
            </xsd:choice>
        </xsd:sequence>
        <xsd:attribute name="legalAddressType" type="stf:OECDLegalAddressType_EnumType" use="optional">

        </xsd:attribute>
    </xsd:complexType>

输出为:

...
    @XmlElementRefs({
        @XmlElementRef(name = "CountryCode", namespace = "urn:oecd:ties:dpi:v1", type = JAXBElement.class, required = false),
        @XmlElementRef(name = "AddressFree", namespace = "urn:oecd:ties:dpi:v1", type = JAXBElement.class, required = false),
        @XmlElementRef(name = "AddressFix", namespace = "urn:oecd:ties:dpi:v1", type = JAXBElement.class, required = false)
    })
    protected List<JAXBElement<?>> content;
...

当我们尝试将 java 转换为 xml 时,应用程序会引发异常:

Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `jakarta.xml.bind.JAXBElement` (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)

有办法解决吗?

我们尝试过使用 xjb 绑定,尝试重命名属性或设置我们自己的实现,但看起来 xpath(它是一个 wsdl,导入一个 xsd,也导入另一个 xsd)没有被拾取。

我们期待一个以 getCountryCodeOrAddressFreeOrAddressFix() 方式提供列表的类

spring-boot jaxb wsdl wsdl2java
1个回答
0
投票

好的,所以我们最终使用了 bindings.xjb 并用我们自己的类替换生成的类。

<jaxb:bindings version="3.0"
               xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb"
               xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <jaxb:bindings
            schemaLocation="https://www2.agenciatributaria.gob.es/static_files/common/internet/dep/taiif/xsd/ixgd/DPIXML_v1.0.xsd"
            node="xsd:complexType[@name='Address_Type']">
        <jaxb:class ref="com.package.name.to.our.implementation.AddressType"/>
    </jaxb:bindings>

</jaxb:bindings>

在 build.gradle 中

wsdl2java {
    cxfVersion.set("4.0.3")
    wsdlDir.set(layout.projectDirectory.dir("src/main/resources/wsdl"))
    generatedSourceDir.set(layout.buildDirectory.dir("aeat/generated"))
    bindingFile.set(layout.projectDirectory.file("src/main/resources/wsdl/binding.xjb"))
}

我们确实尝试使用 Laurent 建议的简化插件,但我们收到了诸如“编译器无法支持此简化:as-element-property 自定义”之类的错误

© www.soinside.com 2019 - 2024. All rights reserved.