我正在尝试创建一个可以同时包含元素和值的java / jaxb类 .
我想在类A的列表中读取类的属性,并输出为类A本身的值 .
这是XML:
我必须阅读:
并 生产环境 :
ERR1
这是我的错误类 - 工作正常:
@XmlRootElement(name = "error")
public class Error implements Serializable {
private String id;
@XmlAttribute(name ="id")
public String getId() {
return id;
}
public void setId(String id ){
this.id = id;
}
}
我的设备类:
@XmlRootElement(name = "device")
public class Device implements Serializable {
private String id;
private String device;
private ArrayList errorList;
@XmlElement
public ArrayList getErrorList() {
return errorList;
}
@XmlAttribute(name = "id")
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@XmlValue
public String getDevice(){
return this.device;
}
}
Jaxb抱怨我不能在同一个类中同时拥有xmlelement(Error)和xmlvalue
"If a class has @XmlElement property, it cannot have @XmlValue property."
我如何正确建模/注释这个以允许我读取错误xml标记的属性并将其生成为设备标记的值?