Package org.hibernate.validator
Interface HibernateValidatorContext
- All Superinterfaces:
ValidatorContext
- All Known Implementing Classes:
PredefinedScopeValidatorContextImpl,ValidatorContextImpl
Represents a Hibernate Validator specific context that is used to create
Validator instances. Adds additional configuration options to those
provided by ValidatorContext.- Author:
- Emmanuel Bernard, Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI, Gunnar Morling, Chris Beckey <cbeckey@paypal.com>
-
Method Summary
Modifier and TypeMethodDescriptionaddValueExtractor(ValueExtractor<?> extractor) Adds a value extractor to be used by theValidator.allowMultipleCascadedValidationOnReturnValues(boolean allow) Define whether more than one constraint on a return value may be marked for cascading validation are allowed.allowOverridingMethodAlterParameterConstraint(boolean allow) Define whether overriding methods that override constraints should throw aConstraintDefinitionException.allowParallelMethodsDefineParameterConstraints(boolean allow) Define whether parallel methods that define constraints should throw aConstraintDefinitionException.clockProvider(ClockProvider clockProvider) Defines theClockProviderimplementation used by theValidator.Defines the constraint validator factory implementation used by theValidator.constraintValidatorPayload(Object constraintValidatorPayload) Define a payload passed to the constraint validators.enableTraversableResolverResultCache(boolean enabled) Define whether the per validation call caching ofTraversableResolverresults is enabled.failFast(boolean failFast) En- or disables the fail fast mode.messageInterpolator(MessageInterpolator messageInterpolator) Defines the message interpolator implementation used by theValidator.parameterNameProvider(ParameterNameProvider parameterNameProvider) Defines the parameter name provider implementation used by theValidator.showValidatedValuesInTraceLogs(boolean enabled) Define whether values that are currently being validated should be part of the logging at trace level, or not.temporalValidationTolerance(Duration temporalValidationTolerance) Define the temporal validation tolerance i.e. the acceptable margin of error when comparing date/time in temporal constraints.traversableResolver(TraversableResolver traversableResolver) Defines the traversable resolver implementation used by theValidator.Methods inherited from interface jakarta.validation.ValidatorContext
getValidator
-
Method Details
-
messageInterpolator
Description copied from interface:ValidatorContextDefines the message interpolator implementation used by theValidator.If not set or if
nullis passed as a parameter, the message interpolator of theValidatorFactoryis used.- Specified by:
messageInterpolatorin interfaceValidatorContext- Parameters:
messageInterpolator- theMessageInterpolatorused by theValidator- Returns:
- self following the chaining method pattern
-
traversableResolver
Description copied from interface:ValidatorContextDefines the traversable resolver implementation used by theValidator.If not set or if
nullis passed as a parameter, the traversable resolver of theValidatorFactoryis used.- Specified by:
traversableResolverin interfaceValidatorContext- Parameters:
traversableResolver- theTraversableResolverused by theValidator- Returns:
- self following the chaining method pattern
-
constraintValidatorFactory
Description copied from interface:ValidatorContextDefines the constraint validator factory implementation used by theValidator. If not set or ifnullis passed as a parameter, the constraint validator factory of theValidatorFactoryis used.- Specified by:
constraintValidatorFactoryin interfaceValidatorContext- Parameters:
factory- theConstraintValidatorFactoryused by theValidator- Returns:
- self following the chaining method pattern
-
parameterNameProvider
Description copied from interface:ValidatorContextDefines the parameter name provider implementation used by theValidator. If not set or ifnullis passed as a parameter, the parameter name provider of theValidatorFactoryis used.- Specified by:
parameterNameProviderin interfaceValidatorContext- Parameters:
parameterNameProvider- parameter name provider implementation.- Returns:
- self following the chaining method pattern
- Since:
- 5.2
-
clockProvider
Description copied from interface:ValidatorContextDefines theClockProviderimplementation used by theValidator. If not set or ifnullis passed as a parameter, the clock provider of theValidatorFactoryis used.- Specified by:
clockProviderin interfaceValidatorContext- Parameters:
clockProvider-ClockProviderimplementation- Returns:
- self following the chaining method pattern
- Since:
- 6.0
-
addValueExtractor
Description copied from interface:ValidatorContextAdds a value extractor to be used by theValidator. Has priority over any extractor for the same type and type parameter detected through the service loader, given in the XML configuration or configured for the validator factory.- Specified by:
addValueExtractorin interfaceValidatorContext- Parameters:
extractor- value extractor implementation- Returns:
- self following the chaining method pattern
- Since:
- 6.0
-
failFast
En- or disables the fail fast mode. When fail fast is enabled the validation will stop on the first constraint violation detected.- Parameters:
failFast-trueto enable fail fast,falseotherwise.- Returns:
thisfollowing the chaining method pattern
-
allowOverridingMethodAlterParameterConstraint
Define whether overriding methods that override constraints should throw aConstraintDefinitionException. The default value isfalse, i.e. do not allow.See Section 4.5.5 of the JSR 380 specification, specifically
"In sub types (be it sub classes/interfaces or interface implementations), no parameter constraints may be declared on overridden or implemented methods, nor may parameters be marked for cascaded validation. This would pose a strengthening of preconditions to be fulfilled by the caller."
- Parameters:
allow- flag determining whether validation will allow overriding to alter parameter constraints.- Returns:
thisfollowing the chaining method pattern- Since:
- 5.3
-
allowMultipleCascadedValidationOnReturnValues
Define whether more than one constraint on a return value may be marked for cascading validation are allowed. The default value isfalse, i.e. do not allow.See Section 4.5.5 of the JSR 380 specification, specifically
"One must not mark a method return value for cascaded validation more than once in a line of a class hierarchy. In other words, overriding methods on sub types (be it sub classes/interfaces or interface implementations) cannot mark the return value for cascaded validation if the return value has already been marked on the overridden method of the super type or interface."
- Parameters:
allow- flag determining whether validation will allow multiple cascaded validation on return values.- Returns:
thisfollowing the chaining method pattern- Since:
- 5.3
-
allowParallelMethodsDefineParameterConstraints
Define whether parallel methods that define constraints should throw aConstraintDefinitionException. The default value isfalse, i.e. do not allow.See Section 4.5.5 of the JSR 380 specification, specifically
"If a sub type overrides/implements a method originally defined in several parallel types of the hierarchy (e.g. two interfaces not extending each other, or a class and an interface not implemented by said class), no parameter constraints may be declared for that method at all nor parameters be marked for cascaded validation. This again is to avoid an unexpected strengthening of preconditions to be fulfilled by the caller."
- Parameters:
allow- flag determining whether validation will allow parameter constraints in parallel hierarchies- Returns:
thisfollowing the chaining method pattern- Since:
- 5.3
-
enableTraversableResolverResultCache
Define whether the per validation call caching ofTraversableResolverresults is enabled. The default value istrue, i.e. the caching is enabled.This behavior was initially introduced to cache the
JPATraversableResolverresults but the map lookups it introduces can be counterproductive when theTraversableResolvercalls are very fast.- Parameters:
enabled- flag determining whether per validation call caching is enabled forTraversableResolverresults.- Returns:
thisfollowing the chaining method pattern- Since:
- 6.0.3
-
temporalValidationTolerance
@Incubating HibernateValidatorContext temporalValidationTolerance(Duration temporalValidationTolerance) Define the temporal validation tolerance i.e. the acceptable margin of error when comparing date/time in temporal constraints.- Parameters:
temporalValidationTolerance- the tolerance- Returns:
thisfollowing the chaining method pattern- Since:
- 6.0.5
-
constraintValidatorPayload
Define a payload passed to the constraint validators. If the method is called multiple times, only the payload passed last will be propagated.- Parameters:
constraintValidatorPayload- the payload passed to constraint validators- Returns:
thisfollowing the chaining method pattern- Since:
- 6.0.8
-
showValidatedValuesInTraceLogs
Define whether values that are currently being validated should be part of the logging at trace level, or not.- Parameters:
enabled-trueto show the values at trace level,falseotherwise.- Returns:
thisfollowing the chaining method pattern- Since:
- 8.0
-