Hi
I'm rewriting our validation framework to Hibernate Validator. In general, I'm very happy with it, but there's one feature which I really miss.
You see, often a method parameter is actually the same as a property within a class, which already contains validation annotations.
Let's say you have a User class which contains an ID:
Code:
@Nonnull
@Range(min = 1, max = 9999)
// And some other validations
private Integer id;
And then you have a method which finds the user:
Code:
public User findUser(Integer id) { ... }
Using the method validation, you can of course specify:
Code:
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 why in our previous validation framework we had the annotation @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:
Code:
public User findUser(@ValidProperty(User.class) Integer id) { ... }
Of course, it should be possible to use a different parameter name, like:
Code:
public User findUser(@ValidProperty(value=User.class, property="id") Integer userID) { ... }
What do you think?