Interface BaseHibernateValidatorConfiguration<S extends BaseHibernateValidatorConfiguration<S>>
- All Superinterfaces:
Configuration<S>
- All Known Subinterfaces:
HibernateValidatorConfiguration,PredefinedScopeHibernateValidatorConfiguration
- All Known Implementing Classes:
AbstractConfigurationImpl,ConfigurationImpl,PredefinedScopeConfigurationImpl
Should not be used directly, prefer HibernateValidatorConfiguration or
PredefinedScopeHibernateValidatorConfiguration.
- Author:
- Emmanuel Bernard, Gunnar Morling, Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI, Hardy Ferentschik, Chris Beckey <cbeckey@paypal.com>
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringProperty corresponding to theallowMultipleCascadedValidationOnReturnValues(boolean)method.static final StringProperty corresponding to theallowParallelMethodsDefineParameterConstraints(boolean)method.static final StringProperty corresponding to theallowOverridingMethodAlterParameterConstraint(boolean)method.static final StringProperty for configuring the Expression Language feature level for constraints, allowing to define which Expression Language features are available for message interpolation.static final StringDeprecated.planned for removal.static final StringProperty for configuring constraint mapping contributors, allowing to set up one or more constraint mappings for the default validator factory.static final StringProperty for configuring the Expression Language feature level for custom violations, allowing to define which Expression Language features are available for message interpolation.static final StringProperty corresponding to theenableTraversableResolverResultCache(boolean).static final StringProperty corresponding to thefailFast(boolean)method.static final StringProperty for configuring the getter property selection strategy, allowing to set which rules will be applied to determine if a method is a valid JavaBean getter.static final StringProperty for configuring the locale resolver, allowing to select an implementation ofLocaleResolverwhich will be used for locale resolution when interpolating a message.static final StringProperty for configuring the property node name provider, allowing to select an implementation ofPropertyNodeNameProviderwhich will be used for property name resolution when creating a property path.static final StringProperty for configuring the script evaluator factory, allowing to set up which factory will be used to createScriptEvaluators for evaluation of script expressions inScriptAssertandParameterScriptAssertconstraints.static final StringProperty for trace level logs to include values under validation when constraint checks are executed.static final StringProperty for configuring temporal validation tolerance, allowing to set the acceptable margin of error when comparing date/time in temporal constraints. -
Method Summary
Modifier and TypeMethodDescriptionaddMapping(ConstraintMapping mapping) Adds the specifiedConstraintMappinginstance to the configuration.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.beanMetaDataClassNormalizer(BeanMetaDataClassNormalizer beanMetaDataClassNormalizer) constraintExpressionLanguageFeatureLevel(ExpressionLanguageFeatureLevel expressionLanguageFeatureLevel) Allows setting the Expression Language feature level for message interpolation of constraint messages.constraintValidatorPayload(Object constraintValidatorPayload) Allows to set a payload which will be passed to the constraint validators.Creates a new constraint mapping which can be used to programmatically configure the constraints for given types.customViolationExpressionLanguageFeatureLevel(ExpressionLanguageFeatureLevel expressionLanguageFeatureLevel) Allows setting the Expression Language feature level for message interpolation of custom violation messages.defaultLocale(Locale defaultLocale) Allows setting the default locale used to interpolate the constraint violation messages.enableTraversableResolverResultCache(boolean enabled) Define whether the per validation call caching ofTraversableResolverresults is enabled.externalClassLoader(ClassLoader externalClassLoader) Sets the class loader to be used for loading user-provided resources: XML descriptors (META-INF/validation.xmlas well as XML constraint mappings) classes specified by name in XML descriptors (e.g.failFast(boolean failFast) En- or disables the fail fast mode.Returns theResourceBundleLocatorused by thedefault message interpolatorto load user-provided resource bundles.Set<ValueExtractor<?>>Returns the defaultValueExtractorimplementations as per the specification.getterPropertySelectionStrategy(GetterPropertySelectionStrategy getterPropertySelectionStrategy) Allows to set a getter property selection strategy defining the rules determining if a method is a getter or not.localeResolver(LocaleResolver localeResolver) Allows setting a locale resolver, defining how the locale will be resolved when interpolating the message of a constraint violation.default SAllows setting the list of the locales supported by this ValidatorFactory.Allows setting the list of the locales supported by this ValidatorFactory.propertyNodeNameProvider(PropertyNodeNameProvider propertyNodeNameProvider) Allows to set a property node name provider, defining how the name of a property node will be resolved when constructing a property path as the one returned byConstraintViolation.getPropertyPath().scriptEvaluatorFactory(ScriptEvaluatorFactory scriptEvaluatorFactory) Allows to specify a customScriptEvaluatorFactoryresponsible for creatingScriptEvaluators used to evaluate script expressions forScriptAssertandParameterScriptAssertconstraints.showValidatedValuesInTraceLogs(boolean enabled) Allows setting the logging configuration that would include validated values in trace level logs.temporalValidationTolerance(Duration temporalValidationTolerance) Allows to set the acceptable margin of error when comparing date/time in temporal constraints such asPast/PastOrPresentandFuture/FutureOrPresent.Methods inherited from interface jakarta.validation.Configuration
addMapping, addProperty, addValueExtractor, buildValidatorFactory, clockProvider, constraintValidatorFactory, getBootstrapConfiguration, getDefaultClockProvider, getDefaultConstraintValidatorFactory, getDefaultMessageInterpolator, getDefaultParameterNameProvider, getDefaultTraversableResolver, ignoreXmlConfiguration, messageInterpolator, parameterNameProvider, traversableResolver
-
Field Details
-
FAIL_FAST
- See Also:
-
ALLOW_PARAMETER_CONSTRAINT_OVERRIDE
Property corresponding to theallowOverridingMethodAlterParameterConstraint(boolean)method. Acceptstrueorfalse. Defaults tofalse.- See Also:
-
ALLOW_MULTIPLE_CASCADED_VALIDATION_ON_RESULT
Property corresponding to theallowMultipleCascadedValidationOnReturnValues(boolean)method. Acceptstrueorfalse. Defaults tofalse.- See Also:
-
ALLOW_PARALLEL_METHODS_DEFINE_PARAMETER_CONSTRAINTS
Property corresponding to theallowParallelMethodsDefineParameterConstraints(boolean)method. Acceptstrueorfalse. Defaults tofalse.- See Also:
-
CONSTRAINT_MAPPING_CONTRIBUTOR
Deprecated.planned for removal. Use hibernate.validator.constraint_mapping_contributors instead.- Since:
- 5.2
- See Also:
-
CONSTRAINT_MAPPING_CONTRIBUTORS
Property for configuring constraint mapping contributors, allowing to set up one or more constraint mappings for the default validator factory. Accepts a String with the comma separated fully-qualified class names of one or moreConstraintMappingContributorimplementations.- Since:
- 5.3
- See Also:
-
ENABLE_TRAVERSABLE_RESOLVER_RESULT_CACHE
Property corresponding to theenableTraversableResolverResultCache(boolean). Acceptstrueorfalse. Defaults totrue.- Since:
- 6.0.3
- See Also:
-
SCRIPT_EVALUATOR_FACTORY_CLASSNAME
Property for configuring the script evaluator factory, allowing to set up which factory will be used to createScriptEvaluators for evaluation of script expressions inScriptAssertandParameterScriptAssertconstraints. A fully qualified name of a class implementingScriptEvaluatorFactoryis expected as a value.- Since:
- 6.0.3
- See Also:
-
TEMPORAL_VALIDATION_TOLERANCE
Property for configuring temporal validation tolerance, allowing to set the acceptable margin of error when comparing date/time in temporal constraints. In milliseconds.- Since:
- 6.0.5
- See Also:
-
GETTER_PROPERTY_SELECTION_STRATEGY_CLASSNAME
Property for configuring the getter property selection strategy, allowing to set which rules will be applied to determine if a method is a valid JavaBean getter.- Since:
- 6.1.0
- See Also:
-
PROPERTY_NODE_NAME_PROVIDER_CLASSNAME
Property for configuring the property node name provider, allowing to select an implementation ofPropertyNodeNameProviderwhich will be used for property name resolution when creating a property path.- Since:
- 6.1.0
- See Also:
-
LOCALE_RESOLVER_CLASSNAME
Property for configuring the locale resolver, allowing to select an implementation ofLocaleResolverwhich will be used for locale resolution when interpolating a message.- Since:
- 6.1.1
- See Also:
-
CONSTRAINT_EXPRESSION_LANGUAGE_FEATURE_LEVEL
Property for configuring the Expression Language feature level for constraints, allowing to define which Expression Language features are available for message interpolation.This property only affects the EL feature level of "static" constraint violation messages. In particular, it doesn't affect the default EL feature level for custom violations. Refer to
CUSTOM_VIOLATION_EXPRESSION_LANGUAGE_FEATURE_LEVELto configure that.- Since:
- 6.2
- See Also:
-
CUSTOM_VIOLATION_EXPRESSION_LANGUAGE_FEATURE_LEVEL
Property for configuring the Expression Language feature level for custom violations, allowing to define which Expression Language features are available for message interpolation.- Since:
- 6.2
- See Also:
-
SHOW_VALIDATED_VALUE_IN_TRACE_LOGS
Property for trace level logs to include values under validation when constraint checks are executed.- Since:
- 8.0
- See Also:
-
-
Method Details
-
getDefaultResourceBundleLocator
ResourceBundleLocator getDefaultResourceBundleLocator()Returns the
ResourceBundleLocatorused by thedefault message interpolatorto load user-provided resource bundles. In conformance with the specification this default locator retrieves the bundle "ValidationMessages".This locator can be used as delegate for custom locators when setting a customized
ResourceBundleMessageInterpolator:HibernateValidatorConfiguration configure = Validation.byProvider(HibernateValidator.class).configure(); ResourceBundleLocator defaultResourceBundleLocator = configure.getDefaultBundleLocator(); ResourceBundleLocator myResourceBundleLocator = new MyResourceBundleLocator(defaultResourceBundleLocator); configure.messageInterpolator( new ResourceBundleMessageInterpolator(myResourceBundleLocator));- Returns:
- The default
ResourceBundleLocator. Never null.
-
createConstraintMapping
ConstraintMapping createConstraintMapping()Creates a new constraint mapping which can be used to programmatically configure the constraints for given types. After the mapping has been set up, it must be added to this configuration viaaddMapping(ConstraintMapping).- Returns:
- A new constraint mapping.
-
getDefaultValueExtractors
Returns the defaultValueExtractorimplementations as per the specification.- Returns:
- the default
ValueExtractorimplementations compliant with the specification - Since:
- 6.0
-
addMapping
Adds the specifiedConstraintMappinginstance to the configuration. Constraints configured inmappingwill be added to the constraints configured via annotations and/or xml.- Parameters:
mapping-ConstraintMappinginstance containing programmatic configured constraints- Returns:
thisfollowing the chaining method pattern- Throws:
IllegalArgumentException- ifmappingisnull
-
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
-
externalClassLoader
Sets the class loader to be used for loading user-provided resources:- XML descriptors (
META-INF/validation.xmlas well as XML constraint mappings) - classes specified by name in XML descriptors (e.g. custom message interpolators etc.)
- the
ValidationMessagesresource bundle
- Parameters:
externalClassLoader- The class loader for loading user-provided resources.- Returns:
thisfollowing the chaining method pattern- Since:
- 5.2
- XML descriptors (
-
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
-
scriptEvaluatorFactory
Allows to specify a customScriptEvaluatorFactoryresponsible for creatingScriptEvaluators used to evaluate script expressions forScriptAssertandParameterScriptAssertconstraints.- Parameters:
scriptEvaluatorFactory- theScriptEvaluatorFactoryto be used- Returns:
thisfollowing the chaining method pattern- Since:
- 6.0.3
-
temporalValidationTolerance
Allows to set the acceptable margin of error when comparing date/time in temporal constraints such asPast/PastOrPresentandFuture/FutureOrPresent.- Parameters:
temporalValidationTolerance- the acceptable tolerance- Returns:
thisfollowing the chaining method pattern- Since:
- 6.0.5
-
constraintValidatorPayload
Allows to set a payload which will be 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
-
getterPropertySelectionStrategy
@Incubating S getterPropertySelectionStrategy(GetterPropertySelectionStrategy getterPropertySelectionStrategy) Allows to set a getter property selection strategy defining the rules determining if a method is a getter or not.- Parameters:
getterPropertySelectionStrategy- theGetterPropertySelectionStrategyto be used- Returns:
thisfollowing the chaining method pattern- Since:
- 6.1.0
-
propertyNodeNameProvider
Allows to set a property node name provider, defining how the name of a property node will be resolved when constructing a property path as the one returned byConstraintViolation.getPropertyPath().- Parameters:
propertyNodeNameProvider- thePropertyNodeNameProviderto be used- Returns:
thisfollowing the chaining method pattern- Since:
- 6.1.0
-
locales
Allows setting the list of the locales supported by this ValidatorFactory.Can be used for advanced locale resolution and/or to force the initialization of the resource bundles at bootstrap.
If not set, defaults to a singleton containing
Locale.getDefault().- Since:
- 6.1.1
-
locales
Allows setting the list of the locales supported by this ValidatorFactory.Can be used for advanced locale resolution and/or to force the initialization of the resource bundles at bootstrap.
If not set, defaults to a singleton containing
Locale.getDefault().- Since:
- 6.1.1
-
defaultLocale
Allows setting the default locale used to interpolate the constraint violation messages.If not set, defaults to the system locale obtained via
Locale.getDefault().- Since:
- 6.1.1
-
localeResolver
Allows setting a locale resolver, defining how the locale will be resolved when interpolating the message of a constraint violation.- Parameters:
localeResolver- theLocaleResolverto be used- Returns:
thisfollowing the chaining method pattern- Since:
- 6.1.1
-
beanMetaDataClassNormalizer
-
constraintExpressionLanguageFeatureLevel
@Incubating S constraintExpressionLanguageFeatureLevel(ExpressionLanguageFeatureLevel expressionLanguageFeatureLevel) Allows setting the Expression Language feature level for message interpolation of constraint messages.This is the feature level used for messages hardcoded inside the constraint declaration.
If you are creating custom constraint violations, Expression Language support needs to be explicitly enabled and use the safest feature level by default if enabled.
- Parameters:
expressionLanguageFeatureLevel- theExpressionLanguageFeatureLevelto be used- Returns:
thisfollowing the chaining method pattern- Since:
- 6.2
-
customViolationExpressionLanguageFeatureLevel
@Incubating S customViolationExpressionLanguageFeatureLevel(ExpressionLanguageFeatureLevel expressionLanguageFeatureLevel) Allows setting the Expression Language feature level for message interpolation of custom violation messages.This is the feature level used for messages of custom violations created by the
ConstraintValidatorContext.- Parameters:
expressionLanguageFeatureLevel- theExpressionLanguageFeatureLevelto be used- Returns:
thisfollowing the chaining method pattern- Since:
- 6.2
-
showValidatedValuesInTraceLogs
Allows setting the logging configuration that would include validated values in trace level logs.By default, values will not be printed to the logs as they might contain sensitive data.
- Parameters:
enabled- flag determining whether validated values will be printed out into trace level logs or not.- Returns:
thisfollowing the chaining method pattern- Since:
- 8.0
-