1 Reply Latest reply on Jul 22, 2011 10:53 AM by maxandersen

    JBoss 7 AS RESTEasy issue with generic type arguments

    jantimw

      Before I recently migrated from JBoss 6 to 7, I was using JAX-RS for my RESTful services and everything went fine. Now that I am working with JBoss 7 I noticed that I can use the build in RESTEasy for my purposes. But unfortunately there seems to be an issue with generic types when used in annotated POST or PUT methods.

       

      To make things clear, I created a small and easy example of what was working for me before but no longer does:

       

      @Path("/g") 
      public abstract class GenericResource<T extends Person> { 
      
          @POST 
          @Path("/add") 
          @Consumes("application/json") 
          @Produces("application/json") 
          public String doPost(T person) {          // The use of a generic type as argument causes an error
              return "success"; 
          } 
      
      
          @GET 
          @Produces("application/json") 
          public T doGet() { 
              @SuppressWarnings("unchecked") 
              T p = (T) new PersonImpl("TestPerson");  
      
              return p; 
          } 
      
      }
      
      

       

      As you can see, I just build an abstract class with a generic type T and annotated two methods, one with "POST" and one with "GET". This example worked fine with JBoss 6 and JAX-RS, but now I get the following error on sending any request (get or post) through RESTEeasy to this class:

       

      Allocate exception for servlet javax.ws.rs.core.Application: java.lang.RuntimeException: Unable to determine value of type parameter T 
          at org.jboss.resteasy.util.Types.getActualValueOfTypeVariable(Types.java:319) [resteasy-jaxrs-2.2.1.GA.jar:] 
          at org.jboss.resteasy.core.MethodInjectorImpl.<init>(MethodInjectorImpl.java:65) [resteasy-jaxrs-2.2.1.GA.jar:] 
          at org.jboss.resteasy.core.InjectorFactoryImpl.createMethodInjector(InjectorFactoryImpl.java:55) [resteasy-jaxrs-2.2.1.GA.jar:] 
          at org.jboss.resteasy.core.ResourceMethod.<init>(ResourceMethod.java:71) [resteasy-jaxrs-2.2.1.GA.jar:] 
          at org.jboss.resteasy.core.ResourceMethodRegistry.processMethod(ResourceMethodRegistry.java:178) [resteasy-jaxrs-2.2.1.GA.jar:] 
          at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:123) [resteasy-jaxrs-2.2.1.GA.jar:] 
          at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:106) [resteasy-jaxrs-2.2.1.GA.jar:] 
          at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:83) [resteasy-jaxrs-2.2.1.GA.jar:] 
          at org.jboss.resteasy.core.ResourceMethodRegistry.addPerRequestResource(ResourceMethodRegistry.java:72) [resteasy-jaxrs-2.2.1.GA.jar:] 
          at org.jboss.resteasy.spi.ResteasyDeployment.registration(ResteasyDeployment.java:367) [resteasy-jaxrs-2.2.1.GA.jar:] 
          at org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:225) [resteasy-jaxrs-2.2.1.GA.jar:] 
          at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.init(ServletContainerDispatcher.java:67) [resteasy-jaxrs-2.2.1.GA.jar:] 
          at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.init(HttpServletDispatcher.java:36) [resteasy-jaxrs-2.2.1.GA.jar:] 
          at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1202) [jbossweb-7.0.0.CR4.jar:7.0.0.Final] 
          at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:952) [jbossweb-7.0.0.CR4.jar:7.0.0.Final] 
          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:188) [jbossweb-7.0.0.CR4.jar:7.0.0.Final] 
          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.0.CR4.jar:7.0.0.Final] 
          at org.jboss.as.web.NamingValve.invoke(NamingValve.java:57) [jboss-as-web-7.0.0.Final.jar:7.0.0.Final] 
          at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:49) [jboss-as-jpa-7.0.0.Final.jar:7.0.0.Final] 
          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:154) [jbossweb-7.0.0.CR4.jar:7.0.0.Final] 
          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.0.CR4.jar:7.0.0.Final] 
          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.0.CR4.jar:7.0.0.Final] 
          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [jbossweb-7.0.0.CR4.jar:7.0.0.Final] 
          at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.0.CR4.jar:7.0.0.Final] 
          at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:667) [jbossweb-7.0.0.CR4.jar:7.0.0.Final] 
          at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [jbossweb-7.0.0.CR4.jar:7.0.0.Final] 
          at java.lang.Thread.run(Thread.java:662) [:1.6.0_26] 
      

       

      If I remove the POST-method, at least the GET-request ist working correctly. Although changing the argument to a type that is not generic fixes the error but that is no long term solution for my problem. Am I doing something wrong or is it a bug that is already known?

       

      Best Regards