我有这个类颜色:
public class Color {
private String name;
private List<String> usedInShapes;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<String> getUsedInShapes() {
if (usedInShapes== null) {
return null;
}
return new ArrayList<String>(usedInShapes);
}
}
并返回此 bean 并在具有 Color 对象列表的包装器上返回
public class ColorListResponse {
private final List<Color > colorList;
@XmlElement(required=true)
public List<Color> getColorList() {
return colorList;
}
}
当调用该方法时,用户会收到类似的响应
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getColorsResponse xmlns:ns2="http://example.com/ws">
<return>
<colorList>
<name>YELLOW</name>
</colorList>
<colorList>
<name>BLUE</name>
</colorList>
<colorList>
<name>RED</name>
</colorList>
<colorList>
<name>BROWN</name>
</colorList>
</return>
</ns2:getColorsResponse>
</S:Body>
</S:Envelope>
我需要的是这样的:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getColorsResponse xmlns:ns2="http://example.com/ws">
<return>
<colorList>YELLOW</colorList>
<colorList>BLUE</colorList>
<colorList>RED</colorList>
<colorList>BROWN</colorList>
</return>
</ns2:getColorsResponse>
</S:Body>
</S:Envelope>
我一直在尝试弄乱注释,但没有成功......