Skip to content

Configuration

Everything is fixed when the validator is built. BeanValidator.builder() and the bootstrap’s RuliiConfiguration take the same options, the latter also the specification’s clockProvider and properties.

Option What it does
registry(RuleRegistry) Where @Validate names resolve. Without one, the registry of the context the validation runs in.
failFast(boolean) Stop at the first violation. On the bootstrap path also the properties rulii.validation.fail_fast and hibernate.validator.fail_fast.
mapper(ConstraintMapper) How a constraint annotation becomes rules; add your own or replace a built-in mapping. mappers(ConstraintMapperRegistry) on the builder replaces the whole registry.
extractor(ValueExtractor) / addValueExtractor Value extraction for a container type of your own. extractors(ValueExtractorRegistry) on the builder replaces the whole registry. On the bootstrap path extractors are also discovered through META-INF/services.
constraintValidatorFactory, messageInterpolator, traversableResolver, parameterNameProvider The specification’s hooks, consulted as specified.
clockProvider (configuration only) The clock the temporal constraints use. On the builder the clock comes from the context options.
options(RuleContextOptions) The rulii context options validation runs with: matching strategy, message resolver, tracer, clock, locale, converter registry, object factory, executor.
BeanValidator validator = BeanValidator.builder()
.registry(registry)
.failFast(false)
.mapper(skuMapper)
.extractor(new MultimapValueExtractor())
.options(RuleContextOptions.builder()
.tracer(tracer)
.clock(Clock.systemUTC())
.build())
.build();

Validation.byProvider(RuliiValidationProvider.class).configure() returns a RuliiConfiguration, which adds the rulii options to the specification’s Configuration:

ValidatorFactory factory = Validation.byProvider(RuliiValidationProvider.class)
.configure()
.registry(registry)
.failFast(true)
.mapper(skuMapper)
.options(options)
.clockProvider(() -> Clock.systemUTC())
.addValueExtractor(new MultimapValueExtractor())
.messageInterpolator(interpolator)
.buildValidatorFactory();
Validator validator = factory.getValidator();
BeanValidator rulii = validator.unwrap(BeanValidator.class);

Validation.buildDefaultValidatorFactory(), ValidatorFactory, ValidatorContext (usingContext()), unwrap and close work as specified. addMapping(InputStream) throws a ValidationException and META-INF/validation.xml is never read; ignoreXmlConfiguration() is accepted and changes nothing.

Validation runs on a rulii RuleContext built from the RuleContextOptions you give (or rulii’s defaults). This is where the rulii-side behaviour is tuned:

  • Tracer: a Tracer sees every constraint rule as it runs.
  • Message resolver: rulii’s MessageResolver is consulted for error codes, after ValidationMessages.properties.
  • Clock and locale: the clock the temporal constraints compare against, and the locale messages are interpolated in when the call gives none.
  • Converter registry: converts @Bind literals to their declared type.
  • Object factory: creates ConstraintValidator instances through the default ConstraintValidatorFactory; with rulii-spring it is the Spring object factory, so validators are Spring beans.
  • Rule registry: the fallback for @Validate names when the validator has no registry of its own.
Property Where Meaning
rulii.validation.fail_fast addProperty on the configuration Same as failFast(true). hibernate.validator.fail_fast is honoured too.
rulii.script.defaultLanguage System property, or application.properties with rulii-spring The scripting language of @Expr and @Bind(expr) declarations that name none and have no @ExprDefaults in scope.
rulii.validation.enabled, rulii.validation.failFast application.properties with rulii-spring See Spring Boot Integration.