使用 Jaxws 在 Soap Response 中添加额外的标签或元素
Add an extra tag or element in Soap Response using Jaxws
我正在使用 Spring-Cxf 开发一项肥皂服务。我的回复结构如下
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "response", propOrder = {
"name",
"addressList"
})
public class Response
{
private String name;
private List<Address> addressList;
}
-- getter and setter follows
目前的反应是
<response>
<name>RASSI ANDREA</name>
<addressList type="1">
<address>Address 1</address>
<address>Address 2</address>
<address>Address 3</address>
</addressList>
<addressList type="2">
<address>Address 4</address>
<address>Address 5</address>
<address>Address 6</address>
</addressList>
</response>
但我需要的实际响应结构在添加新标签 'row' 的下方。
<response>
<name>RASSI ANDREA</name>
<row>
<addressList type="1">
<address>Address 1</address>
<address>Address 2</address>
<address>Address 3</address>
</addressList>
</row>
<row>
<addressList type="2">
<address>Address 4</address>
<address>Address 5</address>
<address>Address 6</address>
</addressList>
</row>
</response>
任何人都可以解释我应该在哪里进行更改才能实现此目的吗?注释中的任何更改或创建一个新的 class 作为 'row'(尽管我猜这将是一个糟糕的方法)
将注释 @XmlElementWrapper(name="row")
添加到您的 addressList
会将 <row>
标签添加到您的 XML。试一试。
您需要添加以下语句:
import javax.xml.bind.annotation.XmlElementWrapper;
public class Response {
private String name;
@XmlElementWrapper(name="row") // Add this line here
private List<Address> addressList;
}
我正在使用 Spring-Cxf 开发一项肥皂服务。我的回复结构如下
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "response", propOrder = {
"name",
"addressList"
})
public class Response
{
private String name;
private List<Address> addressList;
}
-- getter and setter follows
目前的反应是
<response>
<name>RASSI ANDREA</name>
<addressList type="1">
<address>Address 1</address>
<address>Address 2</address>
<address>Address 3</address>
</addressList>
<addressList type="2">
<address>Address 4</address>
<address>Address 5</address>
<address>Address 6</address>
</addressList>
</response>
但我需要的实际响应结构在添加新标签 'row' 的下方。
<response>
<name>RASSI ANDREA</name>
<row>
<addressList type="1">
<address>Address 1</address>
<address>Address 2</address>
<address>Address 3</address>
</addressList>
</row>
<row>
<addressList type="2">
<address>Address 4</address>
<address>Address 5</address>
<address>Address 6</address>
</addressList>
</row>
</response>
任何人都可以解释我应该在哪里进行更改才能实现此目的吗?注释中的任何更改或创建一个新的 class 作为 'row'(尽管我猜这将是一个糟糕的方法)
将注释 @XmlElementWrapper(name="row")
添加到您的 addressList
会将 <row>
标签添加到您的 XML。试一试。
您需要添加以下语句:
import javax.xml.bind.annotation.XmlElementWrapper;
public class Response {
private String name;
@XmlElementWrapper(name="row") // Add this line here
private List<Address> addressList;
}