JAX-RS: Lesson Learned – JaxbAnnotationIntrospector.findAnnotation:909′ java.lang.NullPointerException

I recently was working with a colleague that was building a quick (and dirty) web project with Java API for RESTful Web Services (JAX-RS).

We ran into an issue (which we realized later was due to rushing).   Exception thrown by application class ‘org.codehaus.jackson.xc.JaxbAnnotationIntrospector.findAnnotation:909
java.lang.NullPointerException

We built an Application config (see any issue yet? ) Hint. Look Ma… No Package.


The @ApplicationPath is set to jaxrs, and could be changed to any one to meet your needs.

I added the config to the web.xml.
        <init-param>
                <param-name>javax.ws.rs.Application</param-name>
                <param-value>Demo</param-value>
        </init-param>

We built a quick demo/entity class (Still using the Default package. )  The Entity Class is in default package, and just holds a string.

When we navigate to the test project / REST interface – http://localhost:9080/JaxRsExample/rest/demo/demo

We see a NullPointerException
Launching defaultServer (WebSphere Application Server 8.5.5.2/wlp-1.0.5.cl50220140403-1858) on IBM J9 VM, version pwa6470sr5-20130619_01 (SR5) (en_US)
[AUDIT   ] CWWKE0001I: The server defaultServer has been launched.
[AUDIT   ] CWWKZ0058I: Monitoring dropins for applications.
[AUDIT   ] CWWKT0016I: Web application available (default_host): http://localhost:9080/JaxRsExample/
[AUDIT   ] CWWKZ0003I: The application JaxRsExample updated in 0.037 seconds.
[ERROR   ] An unhandled exception occurred which will be propagated to the container.
[ERROR   ] SRVE0777E: Exception thrown by application class ‘org.codehaus.jackson.xc.JaxbAnnotationIntrospector.findAnnotation:909
java.lang.NullPointerException
        at org.codehaus.jackson.xc.JaxbAnnotationIntrospector.findAnnotation(JaxbAnnotationIntrospector.java:909)
        at org.codehaus.jackson.xc.JaxbAnnotationIntrospector.findAccessType(JaxbAnnotationIntrospector.java:321)
        at org.codehaus.jackson.xc.JaxbAnnotationIntrospector.findAutoDetectVisibility(JaxbAnnotationIntrospector.java:256)
        at org.codehaus.jackson.map.AnnotationIntrospector$Pair.findAutoDetectVisibility(AnnotationIntrospector.java:808)
        at org.codehaus.jackson.map.ser.BeanSerializerFactory.findBeanProperties(BeanSerializerFactory.java:274)
        at org.codehaus.jackson.map.ser.BeanSerializerFactory.constructBeanSerializer(BeanSerializerFactory.java:216)
        at org.codehaus.jackson.map.ser.BeanSerializerFactory.findBeanSerializer(BeanSerializerFactory.java:139)
        at org.codehaus.jackson.map.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:108)
        at org.codehaus.jackson.map.ser.StdSerializerProvider._createUntypedSerializer(StdSerializerProvider.java:709)
        at org.codehaus.jackson.map.ser.StdSerializerProvider._createAndCacheUntypedSerializer(StdSerializerProvider.java:652)
        at org.codehaus.jackson.map.ser.StdSerializerProvider.findValueSerializer(StdSerializerProvider.java:426)
        at org.codehaus.jackson.map.ser.StdSerializerProvider.findTypedValueSerializer(StdSerializerProvider.java:500)
        at org.codehaus.jackson.map.ser.StdSerializerProvider._serializeValue(StdSerializerProvider.java:312)
        at org.codehaus.jackson.map.ser.StdSerializerProvider.serializeValue(StdSerializerProvider.java:242)
        at org.codehaus.jackson.map.ObjectMapper.writeValue(ObjectMapper.java:1030)
        at org.codehaus.jackson.jaxrs.JacksonJsonProvider.writeTo(JacksonJsonProvider.java:509)
        at org.apache.wink.providers.jackson.WinkJacksonJaxbJsonProvider.writeTo(WinkJacksonJaxbJsonProvider.java:84)
        at org.apache.wink.server.internal.handlers.FlushResultHandler.handleResponse(FlushResultHandler.java:199)
        at org.apache.wink.server.handlers.AbstractHandler.handleResponse(AbstractHandler.java:38)
        at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
        at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
        at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
        at org.apache.wink.server.handlers.AbstractHandler.handleResponse(AbstractHandler.java:39)
        at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
        at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
        at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
        at org.apache.wink.server.handlers.AbstractHandler.handleResponse(AbstractHandler.java:39)
        at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
        at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
        at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
        at org.apache.wink.server.internal.log.Responses.handleResponse(Responses.java:90)
        at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
        at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
        at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
        at org.apache.wink.server.handlers.AbstractHandlersChain.run(AbstractHandlersChain.java:60)
        at org.apache.wink.server.internal.RequestProcessor.handleRequestWithoutFaultBarrier(RequestProcessor.java:212)
        at org.apache.wink.server.internal.RequestProcessor.handleRequest(RequestProcessor.java:154)
        at com.ibm.websphere.jaxrs.server.IBMRestServlet.service(IBMRestServlet.java:106)
        at [internal classes]

[ERROR   ] SRVE0315E: An execption occurred: com.ibm.ws.webcontainer.webapp.WebAppErrorReport: java.lang.NullPointerException
        at org.codehaus.jackson.xc.JaxbAnnotationIntrospector.findAnnotation(JaxbAnnotationIntrospector.java:909)
        at org.codehaus.jackson.xc.JaxbAnnotationIntrospector.findAccessType(JaxbAnnotationIntrospector.java:321)
        at org.codehaus.jackson.xc.JaxbAnnotationIntrospector.findAutoDetectVisibility(JaxbAnnotationIntrospector.java:256)
        at org.codehaus.jackson.map.AnnotationIntrospector$Pair.findAutoDetectVisibility(AnnotationIntrospector.java:808)
        at org.codehaus.jackson.map.ser.BeanSerializerFactory.findBeanProperties(BeanSerializerFactory.java:274)
        at org.codehaus.jackson.map.ser.BeanSerializerFactory.constructBeanSerializer(BeanSerializerFactory.java:216)
        at org.codehaus.jackson.map.ser.BeanSerializerFactory.findBeanSerializer(BeanSerializerFactory.java:139)
        at org.codehaus.jackson.map.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:108)
        at org.codehaus.jackson.map.ser.StdSerializerProvider._createUntypedSerializer(StdSerializerProvider.java:709)
        at org.codehaus.jackson.map.ser.StdSerializerProvider._createAndCacheUntypedSerializer(StdSerializerProvider.java:652)
        at org.codehaus.jackson.map.ser.StdSerializerProvider.findValueSerializer(StdSerializerProvider.java:426)
        at org.codehaus.jackson.map.ser.StdSerializerProvider.findTypedValueSerializer(StdSerializerProvider.java:500)
        at org.codehaus.jackson.map.ser.StdSerializerProvider._serializeValue(StdSerializerProvider.java:312)
        at org.codehaus.jackson.map.ser.StdSerializerProvider.serializeValue(StdSerializerProvider.java:242)
        at org.codehaus.jackson.map.ObjectMapper.writeValue(ObjectMapper.java:1030)
        at org.codehaus.jackson.jaxrs.JacksonJsonProvider.writeTo(JacksonJsonProvider.java:509)
        at org.apache.wink.providers.jackson.WinkJacksonJaxbJsonProvider.writeTo(WinkJacksonJaxbJsonProvider.java:84)
        at org.apache.wink.server.internal.handlers.FlushResultHandler.handleResponse(FlushResultHandler.java:199)
        at org.apache.wink.server.handlers.AbstractHandler.handleResponse(AbstractHandler.java:38)
        at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
        at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
        at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
        at org.apache.wink.server.handlers.AbstractHandler.handleResponse(AbstractHandler.java:39)
        at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
        at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
        at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
        at org.apache.wink.server.handlers.AbstractHandler.handleResponse(AbstractHandler.java:39)
        at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
        at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
        at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
        at org.apache.wink.server.internal.log.Responses.handleResponse(Responses.java:90)
        at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:26)
        at org.apache.wink.server.handlers.ResponseHandlersChain.handle(ResponseHandlersChain.java:22)
        at org.apache.wink.server.handlers.AbstractHandlersChain.doChain(AbstractHandlersChain.java:75)
        at org.apache.wink.server.handlers.AbstractHandlersChain.run(AbstractHandlersChain.java:60)
        at org.apache.wink.server.internal.RequestProcessor.handleRequestWithoutFaultBarrier(RequestProcessor.java:212)
        at org.apache.wink.server.internal.RequestProcessor.handleRequest(RequestProcessor.java:154)
        at com.ibm.websphere.jaxrs.server.IBMRestServlet.service(IBMRestServlet.java:106)
        at [internal classes]
Caused by: java.lang.NullPointerException
        … 40 more

We saw this… and thought about it for a minute…. DON’T EVER USE THE DEFAULT PACKAGE
 Exception thrown by application class ‘org.codehaus.jackson.xc.JaxbAnnotationIntrospector.findAnnotation:909
java.lang.NullPointerException

We changed to package “test” and it all worked.

We hope this helps you all.

http://en.wikipedia.org/wiki/Java_API_for_RESTful_Web_Services