我正在尝试使用 JAXB(在泽西岛内部)进行泛型的多态性:
@XmlRootElement
public class Performance<M extends IMeasurement> {
@XmlAnyElement
private List<M> measurement;
}
@XmlJavaTypeAdapter(MeasurementAbstract.Adapter.class)
public interface IMeasurement<D extends Serializable, V extends Number>
extends Serializable {
D getDate();
void setDate(D date);
V getValue();
void setValue(V value);
}
@XmlTransient
@XmlAccessorType(XmlAccessType.FIELD)
@XmlSeeAlso({MeasurementStringDouble.class, MeasurementStringInteger.class})
public abstract class MeasurementAbstract<D extends Serializable, V extends Number> implements IMeasurement<D, V> {
@XmlElement
protected D date;
@XmlElement
protected V value;
static class Adapter extends XmlAdapter<MeasurementAbstract, IMeasurement> {
public IMeasurement unmarshal(MeasurementAbstract m) { return m; }
public MeasurementAbstract marshal(IMeasurement v) { return (MeasurementAbstract) v; }
}
}
@XmlRootElement
public class MeasurementStringDouble extends MeasurementAbstract<String, Double> {}
@XmlRootElement
public class MeasurementStringInteger extends MeasurementAbstract<String, Integer> {}
我有这个错误:
GRAVE:将异常映射到响应:500(内部服务器错误)javax.ws.rs.WebApplicationException:javax.xml.bind.MarshalException - 带有链接异常:[javax.xml.bind.JAXBException:class org.test.jaxb.MeasurementStringDouble在此上下文中也不知道它的任何超类。]