4
我正在使用RestEasy 2.3.4。我遇到NPE。我有一個通用的基類ValueContainer,我打算擴展爲StringValue,IntegerValue,BooleanValue等,通過用適當的類型替換泛型參數。在JAXB中使用擴展通用類時的NPE/Resteasy
我正在嘗試使用擴展類作爲數據傳輸對象,如下圖所示。但是,我在JAXB處理中遇到了NPE。這意味着,我不會在JAXB中正確對待擴展類。請指教。什麼是正確的做法?謝謝。
基類:
@XmlAccessorType(XmlAccessType.FIELD)
public class ValueContainer<T> {
@XmlAttribute
protected T value;
public ValueContainer() {
}
public ValueContainer(T value) {
this.value = value;
}
public T getValue() {
return value;
}
public void setValue(T value) {
this.value = value;
}
}
實施例擴展類:
@XmlRootElement (name="integervalue")
public class IntegerValue extends ValueContainer<Integer> {
public IntegerValue() {
}
public IntegerValue(Integer value) {
super(value);
}
}
JAX - RS的API接口:
@GET
@Path("/status/{what}")
IntegerValue getStatus(@PathParam ("what")Integer what) ;
的API參數impl:
@Override
public
IntegerValue getStatus(Integer what) {
return new IntegerValue(what);
}
原因NPE,其中配置返回null,當我的瀏覽器調用的http:... /狀態/ 1:
package org.jboss.resteasy.plugins.providers.jaxb;
.....
protected JAXBContext createContextObject(Annotation[] parameterAnnotations, Class... classes) throws JAXBException
{
JAXBConfig config = FindAnnotation.findAnnotation(parameterAnnotations, JAXBConfig.class);
return new JAXBContextWrapper(config, classes);
}