Despite there is Hibernate Validator, I wrote my own. It is adopted to use with SpringFramework WEB MVC framework. Why I not used Hibernate Validator? In Hibernate we have @NotNull, @Length annotations and in @Column we have simmilar annotations. I think that violates DRY principle. Result of Hibernate Validator is array of InvalidValue. For Spring it is better to have messages in ResultBinding.
Usage example:
protected IAnnotationsBasedValidator annotationsBasedValidator;
@Autowired
public void setAnnotationsBasedValidator(IAnnotationsBasedValidator annotationsBasedValidator) {
this.annotationsBasedValidator = annotationsBasedValidator;
}
then somewhere in your code:
annotationsBasedValidator.validate(payment, bindingResult);
As a result bindingResult is filled with validation messages(if there is violated constraints for annotations).
This validator fully utilizes JPA @Column length, nullable, precission, scale, @JoinColumn nullable, @OneToOne , @Embedded. Nested objects for @JoinColumn , @OneToOne , @Embedded is also validated traversing full object tree, except those who is not !propertyInitializationInfo.isInitializaed(cs) (lazy properties).
Additionally it supports annotations: RegexChecker, RangeChecker, BooleanResultChecker to call static method to validate value.
Validator source