The following code works correctly:
import java.io.Serializable;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "data")
public class Data implements Serializable{
private static final long serialVersionUID = 1L;
private long value1;
public Data(){}
public Data(long v1){
this.value1 = v1;
}
public long getValue1() {
return value1;
}
@XmlElement
public void setValue1(long value1) {
this.value1 = value1;
}
}
However this doesn't:
@XmlRootElement(name = "data")
public class Data implements Serializable{
private static final long serialVersionUID = 1L;
private Object value1;
public Data(){}
public Data(Object v1){
this.value1 = v1;
}
public Object getValue1() {
return value1;
}
@XmlElement
public void setValue1(Object value1) {
this.value1 = value1;
}
}
As you can see all I changed was the primitive long
data type to the generic Object
.
This crashes the server, it seems the XML library can't deal with generic objects.
Is there maybe a way to tell the XML library to treat each object as whatever class it is during runtime?