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

genericType argument to MessageBodyWriter is null when type is available

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 2.1-beta-1
    • 2.0.1.GA
    • None
    • None

      Given this resource method:

      @Path("/resource")
      public SomeResource {

      @GET
      List<MyType> getStuff()

      { ... }

      }

      A custom implementation of MessageBodyWriter is passed "null" for its genericType argument (which should contain List<MyType>). This prevents my implementation to detect the type in the collection.

      The negotiation is based on the client setting an Accept header that matches a @Produces on my MessageBodyWriter. The isWriteable() method is called, but my implementation returns false due to the missing genericType argument.

      The problem is located in ResourceMethod line 392:

      Type type = null;

      the "type" variable is assigned null when in fact it could default to the method signature's generic type, which is available in "this.genericReturnType":

      Type type = this.genericReturnType;

      If the entity is a GenericEntity, the value for "type" will later be overridden by what the resource provided.

      Workaround is to add a @Produces annotation to the resource that matches the Accept header. I don't want to do this since the value returned by the resource can be encoded into multiple mime-types by different writers. Adding a new encoding would require that I modify all my resources.

        1. RESTEASY-475.patch
          0.6 kB
          Philippe Laflamme

              patriot1burke@gmail.com Bill Burke (Inactive)
              plaflamme Philippe Laflamme (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: