Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-236

.JettisonMappedContext NulPointerExceptoin

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 1.1.RC2
    • 1.1.RC1
    • jaxrs
    • Compatibility/Configuration

    Description

      @XmlRootElement(name="test")
      public static class Test

      { public int i = 1; }

      @Path("/npe")
      @GET
      @Wrapped()
      @XmlElementWrapper(name="tests")
      public Test[] getTestArray() {
      return new Test[]

      {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?

      Attachments

        Activity

          People

            Unassigned Unassigned
            pbkwee_jira Peter Bryant (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: