我有这样的类(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/