Method Parameter Validation with JSR-303

Tom Tucker picture Tom Tucker · Dec 13, 2010 · Viewed 8.4k times · Source

Is JSR-303 also intended for method parameter validation?

If so, is there any example on the web? The biggest challenge I'm facing is how to get a validator within each method. With Spring 3, doesn't it mean that I'd have to inject virtually every class with a LocalValidatorFactoryBean?

Thanks!

Answer

Gunnar picture Gunnar · Jan 10, 2011

Method level validation will be supported in the upcoming version 4.2 of JSR 303's reference implementation Hibernate Validator.

As pointed out in the previous answer this will allow constraint annotations (built-in as well as custom defined types) to be specified at method parameters and return values to specify pre- and post-conditions for a method's invocation.

Note that HV will only deal with the actual validation of method calls not with triggering such a validation. Validation invocation could be done using AOP or other method interception facilities such as JDK's dynamic proxies.

The JIRA issue for this is HV-347 [1], so you might want to add yourself as watcher to this issue.

[1] http://opensource.atlassian.com/projects/hibernate/browse/HV-347