java - 更改 SOAP xml 响应中的标记名称(类中的字段和响应中的标记必须不同)

标签 java xml web-services soap wsdl2java

我有这样的类(class):

@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 创建者。

最佳答案

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

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

    The Element annotation is used to represent a field or method that appears as an XML element.

  • 将相关的 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;
    ...
}

关于java - 更改 SOAP xml 响应中的标记名称(类中的字段和响应中的标记必须不同),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60228638/

相关文章:

java - 操作栏在 Lollipop 之前的设备中透明

java - 如何在 glassfish 中从一个容器调用另一个容器中的 Web 服务

java - 文件的最后修改时间是一个 13 位数字。这是什么意思?

java - jetty LdapLoginModule : Login Failure: all modules ignored

java - 为什么 Gradle 会解析版本号错误的包?

java - ToggleButton 能否更改同一 Activity 中其他按钮的功能?

java - 转换 ActiveRecord :Relation to java array

python - 使用 python ElementTree 的 itertree 函数并将修改后的树写入输出文件

java - 使用我在 Web 服务器上制作的 Java 程序

linux - 通过网站启动或停止远程机器上的 linux 服务