简体   繁体   English

使用两个类具有相同的 XML 类型名称

[英]Use two classes have the same XML type name

I have this XML:我有这个 XML:

<account-holder>
        <first-name>John</first-name>
        <last-name>Doe</last-name>
        <address>
            <street1>123 anystreet</street1>
        </address>
    </account-holder>
    <shipping>
        <first-name>Manon</first-name>
        <last-name>Mertens</last-name>
        <address>
            <street1>Rue de la Loi 1</street1>
        </address>
        <shipping-method>home_delivery</shipping-method>
    </shipping>

As you can see I have in 2 places tag address .如您所见,我在两个地方有标签address This is the JAXB which I use:这是我使用的 JAXB:

Main Class:主要 Class:

@XmlRootElement(name = "payment")
@XmlAccessorType(XmlAccessType.FIELD)
public class AuthorizeRequest { 

    @XmlElement(name = "account-holder")
    public AccountHolder accountHolder;

    @XmlElement(name = "shipping")
    public Shipping shipping;
}

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class AccountHolder {
    ....
    @XmlElement(name = "address")
    private Address address;
}

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Shipping { 
    ....        
    @XmlElement(name = "address")
    private Address address;
}

Address:地址:

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Address {

    @XmlElement(name = "street1")
    private String street1;

    @XmlElement(name = "street2")
    private String street2;
}

But I get exception:但我得到例外:

Two classes have the same XML type name "{http://www.elastic-payments.com/schema/payment}address". Use @XmlType.name and @XmlType.namespace to assign different names to them.

Do you know how I can fix this issue?你知道我该如何解决这个问题吗?

As the more detailed error message describes, you have (at least) two Address classes正如更详细的错误消息所述,您(至少)有两个Address

org.datalis.gateway.wirecard.models.authorize.request.Address org.datalis.gateway.wirecard.models.authorize.response.Address org.datalis.gateway.wirecard.models.authorize.request.Address org.datalis.gateway.wirecard.models.authorize.response.Address

There are several options有几种选择

  • add @XmlType annotations to them, maybe you can have a namespace for request and one for response向它们添加@XmlType注释,也许您可以有一个命名空间用于请求和一个用于响应
  • Rename the classes to make them unique重命名类以使其唯一
  • Separate the request/response context to make the class unique in that context分离请求/响应上下文以使 class 在该上下文中唯一

暂无
暂无

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

相关问题 两个类具有相同的 XML 类型名称 - Two Classes have same XML type name 两个类具有相同的XML类型名称“objectFactory” - Two classes have the same XML type name “objectFactory” IllegalAnnotationException:两个类具有相同的 XML 类型名称 - IllegalAnnotationException: Two classes have the same XML type name wsdl2java两个类具有相同的XML类型名称“{http://***.***。$。* * / * / / / / / *}} objectFactory” - wsdl2java Two classes have the same XML type name “{http://***.***.***.***/***/***/***}objectFactory” IllegalAnnotationExceptions:两个类具有相同的XML类型名称。 CXF插件生成的代码 - IllegalAnnotationExceptions: Two classes have the same XML type name. Code generated by CXF plugin java +消费SOAP Web服务+“两个类具有相同的XML类型名称……” - java + Consuming a SOAP web service + “Two classes Have the same XML type name …” 获取 JAXB 异常,例如“两个类具有相同的 XML 类型名称...” - Getting the JAXB exception like "Two classes have the same XML type name..." 如果两个库的类具有相同的类和包名称供其内部使用 - if two libraries have classes that have the same class& package name for their internal use jaxb2-maven-plugin 在生成 xsd 时忽略命名空间 - 两个类具有相同的 XML 类型 - jaxb2-maven-plugin ignores namespace when generating xsd - Two classes have the same XML type 如何创建两个具有相同名称,签名和返回类型的方法的类,就像它们实现相同的接口一样 - How to make two classes which both have method with the same name, signature and return type behave like they would implement the same interface
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM