我有以下代码:
@XmlAccessorOrder(XmlAccessOrder.ALPHABETICAL)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "responseClientInfo")
public class SignUpStatus {
@XmlElement(name = "clientCode")
private Integer clientId;
public Integer getClientId() {
return clientId;
}
public void setClientId(Integer clientId) {
this.clientId = clientId;
}
}
我接下来的xml:
<responseClientInfo>
<clientCode>120118</clientCode>
</responseClientInfo>
但我需要接下来:
<responseClientInfo>
<clientInfo>
<clientCode>120118</clientCode>
</clientInfo>
</responseClientInfo>
我知道可以将clientCode包装到类clientInfo中并将这些新类设置为xmlElement,但是可以以更清晰和优雅的方式进行吗?
答案 0 :(得分:1)
尝试使用此XmlElementWrapper
:
@XmlAccessorOrder(XmlAccessOrder.ALPHABETICAL)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "responseClientInfo")
public class SignUpStatus {
@XmlElement(name = "clientCode")
@XmlElementWrapper(name="clientInfo")
private Integer clientId;
public Integer getClientId() {
return clientId;
}
public void setClientId(Integer clientId) {
this.clientId = clientId;
}
}