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

@BeanParam beans should allow private no-arg constructors

    XMLWordPrintable

Details

    Description

      The implementation of org.jboss.resteasy.core.FormInjector requires that the no-arg constructor for beans it injects is public. This is used for injection of QueryParams into BeanParam objects.

      This is not consistent with other areas of JAX-RS where a private no-arg constructor is accepted.

      A resource defined like this would fail startup:

      @GET
      public void searchForHappiness(@BeanParam HappinessParams searchParams) {}
      
      public static final HappinessParams {
        @QueryParam("duration")
        int duration;
        @QueryParam("timeUnit")
        String timeUnit;
      
        @QueryParam("type")
        String type;
      
        private HappinessParams() {}
        public HappinessParams(int duration, String timeUnit) {}
        public HappinessParams(String type) {}
        
      }
      

      The root of the problem is here: https://github.com/resteasy/Resteasy/blob/master/resteasy-jaxrs/src/main/java/org/jboss/resteasy/core/FormInjector.java#L30

      I think this could be solved by changing the getConstructor call to getDeclaredConstructor and calling setAccessible(true) on the constructor returned. Would that be sufficient or is there other process involved in calling setAccessible?

      Attachments

        Activity

          People

            Unassigned Unassigned
            safetytrick Michael Nielson
            Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: