I am using RestEasy 2.3.4. I am facing NPE. I have a common base class ValueContainer, which I plan to extend as StringValue, IntegerValue, BooleanValue, etc., Replacing the general parameter with the corresponding type.
I am experimenting using extension classes as data transfer objects, as shown in the following. However, I encounter NPE when handling JAXB. This means that I am not considering extension classes in JAXB correctly. Please advise. What is the right way to do this? Thanks.
Base class:
@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; } }
An example of an extension class:
@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) ;
Impl API:
@Override public IntegerValue getStatus(Integer what) { return new IntegerValue(what); }
The reason is NPE where config returns null when my browser calls http: ... / status / 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); }
source share