@XmlRootElement(name="test")
public static class Test
@Path("/npe")
@GET
@Wrapped()
@XmlElementWrapper(name="tests")
public Test[] getTestArray() {
return new Test[]
;
}
curl --header "Accept: application/xml" http://localhost:8080/commapp/api/v1/npe ; echo
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><resteasy:collection xmlns:resteasy="http://jboss.org/resteasy"><test><i>1</i></test></resteasy:collection>
curl --header "Accept: application/json" http://localhost:8080/commapp/api/v1/npe ; echo
java.lang.NullPointerException
org.jboss.resteasy.plugins.providers.jaxb.json.JettisonMappedContext.<init>(JettisonMappedContext.java:37)
org.jboss.resteasy.plugins.providers.jaxb.json.JsonJAXBContextFinder.findCacheContext(JsonJAXBContextFinder.java:77)
org.jboss.resteasy.plugins.providers.jaxb.CollectionProvider.writeTo(CollectionProvider.java:164)
org.jboss.resteasy.core.interception.MessageBodyWriterContextImpl.proceed(MessageBodyWriterContextImpl.java:114)
org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor.write(GZIPEncodingInterceptor.java:46)
org.jboss.resteasy.core.interception.MessageBodyWriterContextImpl.proceed(MessageBodyWriterContextImpl.java:120)
org.jboss.resteasy.core.ServerResponse.writeTo(ServerResponse.java:184)
org.jboss.resteasy.core.SynchronousDispatcher.writeJaxrsResponse(SynchronousDispatcher.java:432)
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:395)
Anything I should be doing to prevent the NPE when fetching json arrays?
Workaround is to have a custom MessageBodyWriter
PS: @XmlElementWrapper(name="tests") is ignored as far as I can tell. @Wrapped() is required to get the xml array back. Is this the way you think it should work? @Wrapped appears jboss specific @XmlElementWrapper seems to be a similar but more standardized annotation. Can it not be used instead?