I'm not aware of ready-to-use solution for this, but you could use Hibernate Validator's API for programmatic constraint declaration for this purpose:
- Determine all fields/getters of type String using reflection
- For each of these fields/getters add the required constraint via the API
E.g. like this for the fields:
List<Field> stringFields = ...;
HibernateValidatorConfiguration configuration = Validation
.byProvider( HibernateValidator.class )
.configure();
ConstraintMapping constraintMapping = configuration.createConstraintMapping();
for(Field field : stringFields) {
constraintMapping
.type( MyBean.class )
.property( field.getName(), FIELD )
.constraint( new NotNullDef() )
.constraint( new NotBlankDef() );
}
Validator validator = configuration.addMapping( constraintMapping )
.buildValidatorFactory()
.getValidator();