Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-6380

Support for javax.validation annotations on @PathVariable, @RequestHeader, @RequestParam

    Details

    • Type: New Feature
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 3.0 RC2, 4.0.5
    • Fix Version/s: 5.0 RC1
    • Component/s: Web
    • Labels:
    • Last commented by a User:
      false

      Description

      I thought this was already done, because support for controller method-parameter validation should be available for all parameters.

      I there a reason to exclude annotated (@RequestParam, etc.) method parameters? Is it not possible to validate primitive values?

      Simple example:
      For Paging-Support i need two request parameters: "start" & "size". "start" must have a positive value or 0 and "size" must have a positive value and also a maximum set.

        Issue Links

          Activity

          Hide
          rolltide roll tide added a comment -

          Is this still on roadmap?

          Show
          rolltide roll tide added a comment - Is this still on roadmap?
          Hide
          prattm@gmail.com Michael Pratt added a comment -

          +1, would love to see this as well.

          Show
          prattm@gmail.com Michael Pratt added a comment - +1, would love to see this as well.
          Hide
          rutvijr Rutvij Ravi added a comment - - edited

          In Spring 4.3, constraint annotations work on @PathVariable, @RequestHeader, and @RequestParam parameters when the Controller class is annotated with @Validated and a MethodValidationPostProcessor is registered as a Spring bean in the DispatcherServlet's application context.

          Is this issue for achieving this functionality without @Validated and MethodValidationPostProcessor?

          Since this functionality is usually needed in most projects, i think it makes sense for any constraints on these parameters to be validated by default.

          Show
          rutvijr Rutvij Ravi added a comment - - edited In Spring 4.3, constraint annotations work on @PathVariable, @RequestHeader, and @RequestParam parameters when the Controller class is annotated with @Validated and a MethodValidationPostProcessor is registered as a Spring bean in the DispatcherServlet's application context. Is this issue for achieving this functionality without @Validated and MethodValidationPostProcessor? Since this functionality is usually needed in most projects, i think it makes sense for any constraints on these parameters to be validated by default.
          Hide
          dmitry.bedrin@gmail.com Dmitry Bedrin added a comment -

          MethodValidationPostProcessor doesn't work if Controller implements any interfaces. Unless you force proxyTargetClass behavior in Spring AOP of course.

          Show
          dmitry.bedrin@gmail.com Dmitry Bedrin added a comment - MethodValidationPostProcessor doesn't work if Controller implements any interfaces. Unless you force proxyTargetClass behavior in Spring AOP of course.
          Hide
          juergen.hoeller Juergen Hoeller added a comment -

          Along with the InvocableHandlerMethod revision for SPR-15227, I intend to revisit this one for 5.0. We still don't have a Bean Validation API for validating individual values, however, we have the BV 1.1 {ExecutableValidator}} API available by default now and we can probably do some smart invocation for all method arguments, triggered by a method-level @Validated annotation or possibly even just by the mere presence of parameter-level constraint annotations.

          Show
          juergen.hoeller Juergen Hoeller added a comment - Along with the InvocableHandlerMethod revision for SPR-15227 , I intend to revisit this one for 5.0. We still don't have a Bean Validation API for validating individual values, however, we have the BV 1.1 {ExecutableValidator}} API available by default now and we can probably do some smart invocation for all method arguments, triggered by a method-level @Validated annotation or possibly even just by the mere presence of parameter-level constraint annotations.

            People

            • Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              gbrehmer Gerrit Brehmer
              Last updater:
              Juergen Hoeller
            • Votes:
              58 Vote for this issue
              Watchers:
              60 Start watching this issue

              Dates

              • Created:
                Updated:
                Days since last comment:
                1 week, 1 day ago