我正在尝试将以下xml映射到jaxb。
<SingleRef type="ref" refid="aaa">
<keySet>
<bvId>xxxx</bvId>
<bvGuId>xxxx</bvGuId>
<bvSourceGuId>xxxx</bvSourceGuId>
</kpp:keySet>
<SingleRef>
这是我的等效java类
package com.rahal;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
public class SingleRef {
private String type;
private String refId;
private String bvId;
private String bvGuId;
private String bvSourceGuId;
public String getType() {
return type;
}
@XmlAttribute
public void setType(String type) {
this.type = type;
}
public String getRefId() {
return refId;
}
@XmlAttribute
public void setRefId(String refId) {
this.refId = refId;
}
public String getBvId() {
return bvId;
}
@XmlElementWrapper(name = "keySet")
@XmlElement(name = "bvId")
public void setBvId(String bvId) {
this.bvId = bvId;
}
public String getBvGuId() {
return bvGuId;
}
@XmlElementWrapper(name = "keySet")
@XmlElement(name = "bvGuId")
public void setBvGuId(String bvGuId) {
this.bvGuId = bvGuId;
}
public String getBvSourceGuId() {
return bvSourceGuId;
}
@XmlElementWrapper(name = "keySet")
@XmlElement(name = "bvSourceGuId")
public void setBvSourceGuId(String bvSourceGuId) {
this.bvSourceGuId = bvSourceGuId;
}
}
但它显示一条错误消息,显示@XmlElementWrapper仅允许在集合属性上。还有另一种方法吗?