I'm attempting to create a single java/jaxb class that can have both elements and a value.
I want to read the attribute of a class in a list of class A and output as the value of Class A itself.
This is the XML:
I have to read:
<data>
<device id=”DEV123”>
<error id=”ERR1”/>
</device>
</data>
and produce:
<data>
<device id="DEV123">ERR1</device>
</data>
This is my error class - works fine:
@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;
}
}
My Device class:
@XmlRootElement(name = "device")
public class Device implements Serializable {
private String id;
private String device;
private ArrayList<Error> errorList;
@XmlElement
public ArrayList<Error> 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 complains that I can't have both xmlelement ( Error ) and xmlvalue in the same class
"If a class has @XmlElement property, it cannot have @XmlValue property."
How would I correctly model/annotate this to allow me to read the attribute of the error xml tag and produce it as the value of the device tag?