我正在使用Spring-Cxf开发一个soap服务。在这里,我的响应结构如下所示
@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>
但我需要的实际响应结构位于新标记“排”的位置。已添加。
<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>
任何人都可以解释一下,我应该在哪里进行更改才能实现这一目标?注释中的任何更改或创建新类作为&#39; row&#39;(尽管这会是一种不好的方法)
答案 0 :(得分:1)
将注释@XmlElementWrapper(name="row")
添加到addressList
会将<row>
标记添加到您的XML中。试一试。
您需要添加以下语句:
导入javax.xml.bind.annotation.XmlElementWrapper;
public class Response {
private String name;
@XmlElementWrapper(name="row") // Add this line here
private List<Address> addressList;
}