How to use JSR 303 @Valid annotation to validate primitive types?

java, spring-mvc, validation

Solution

No, it can't be done. It's for bean validation, as described here.

Problem

JSR 303 @Valid annotation can be used to validate input objects to a controller method, as demonstrated on Mkyong.com Is it possible to use @Valid annotation to validate primitive types like int and long[]? If so, how? Here is an example Spring MVC method signature that needs to be validated that the parameters are above 0: ``` @RequestMapping(value = { "/delete" }, method = RequestMethod.POST) ModelAndView deleteBulk(@RequestParam("userId") int userId, @RequestParam("ids") long[] ids) { ```

Original source