|
|
|
The constraints {{@Mod10Check}} and {{@Mod11Check}} should be usable via the [API for programmatic constraint declaration|http://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#section-programmatic-api].
For each constraint we have a [corresponding definition type|https://github.com/hibernate/hibernate-validator/tree/master/engine/src/main/java/org/hibernate/validator/cfg/defs] which allows to configure that constraint via the API in a type-safe manner (actually it was missing for {{@ModCheck}}).
We need {{Mod10CheckDef}} and {{Mod11CheckDef}}; E.g. {{@Mod11Check}} would then be used like this:
{code} HibernateValidatorConfiguration configuration = Validation .byProvider( HibernateValidator.class ).configure();
ConstraintMapping constraintMapping = configuration.createConstraintMapping();
constraintMapping .type( Book.class ) .property( "isbn", FIELD ) .constraint( new Mod11CheckDef() .multiplier( 10 ) .checkDigitPosition( 9 ) .endIndex( 9 ) .treatCheck10As( 'X' ) );
Validator validator = configuration .addMapping( constraintMapping ) .buildValidatorFactory() .getValidator(); {code}
|
|
|
|