【问题标题】:Change tag name in SOAP xml response (field in class and tag in response must be different)更改 SOAP xml 响应中的标签名称(类中的字段和响应中的标签必须不同)
【发布时间】:2020-02-14 14:53:04
【问题描述】:

我有这样的课:

@Root(name = "address_v1", strict = false)
public class AddressItem {

    @Attribute(name = "idAddress")
    private Long addressId;

    @Attribute(name = "idClient")
    private Long clientId;
...
}

我有回应:

...
<ax23:address xsi:type="ax24:AddressItem">
   <ax24:addressId>1111</ax24:addressId>
   <ax24:clientId>1109</ax24:clientId>
...

但我需要:

<ax23:address xsi:type="ax24:AddressItem">
   <ax24:idAddress>1111</ax24:idAddress>
   <ax24:idClient>1109</ax24:idClient>

注释@Attribute(name = "idAddress") 不起作用。 (org.simpleframework.xml.Attribute)。

我使用 wsdl2java 作为 wsdl 创建者。

【问题讨论】:

    标签: java xml web-services soap wsdl2java


    【解决方案1】:

    尝试以下步骤并修改您的 POJO 类,如下所示,

    • 对 XML 元素使用 @Element 注释而不是 @Attribute 注释 (please refer to documentation for more info)

      Element注解用于表示一个字段或方法 显示为 XML 元素。

    • 将相关的xml元素名称设置为@Root@Element注解

    AddressItem.java

    @Root(name = "ax23:address", strict = false)
    public class AddressItem {
    
        @Element(name = "ax24:addressId")
        private Long addressId;
    
        @Element(name = "ax24:clientId")
        private Long clientId;
        ...
    }
    

    【讨论】:

    • 它不起作用 无法满足 @org.simpleframework.xml.Element(name=idAddress, type=void, data=false, required=true) 字段 'addressId' private java.lang .长
    • 你的元素名称是什么,是“idAddress”(@Element(name = "idAddress"))吗?将其更改为“ax24:addressId”(@Element(name = "ax24:addressId"))。请参考上述答案中的 AddressItem.java POJO 类
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-11
    • 1970-01-01
    相关资源
    最近更新 更多