Eric Lewis created New Feature HV-686
Issue Type: New Feature New Feature
Assignee: Unassigned
Created: 30/Jan/13 6:33 AM
Description:

Often a method parameter is actually the same as a property within a class, which already contains validation annotations.

So it would be a great feature to just let the method parameter validation point to that class and that property and let the validator use it.

Let's say you have a User class which contains an ID:

@Nonnull
@Range(min = 1, max = 9999)
// And some other validations
private Integer id;

And then you have a method which finds the user:

public User findUser(Integer id) { ... }

Using the method validation, you can of course specify:

public User findUser(@Nonnull @Range(min = 1, max = 9999) Integer id) { ... }

But that's a violation of the DRY principle, since the validation already exists in the User class.

That's the use case for @ValidProperty. It assumes that the parameter's name is identical to the property of the specified class and then uses that property's validation.

For instance:

public User findUser(@ValidProperty(User.class) Integer id) { ... }

Of course, it should be possible to use a different parameter name, like:

public User findUser(@ValidProperty(value=User.class, property="id") Integer userID) { ... }

The previous validation framework that we used, OVal, had this feature and implemented it by weaving in the necessary code with AspectJ.

Project: Hibernate Validator
Priority: Major Major
Reporter: Eric Lewis
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira