Class WholeBeanValidator
- All Implemented Interfaces:
Validator<Object>
,Serializable
,BiFunction<Object,
ValueContext, ValidationResult>
The BeanValidator
class validates individual bean properties but does not handle "whole bean" validation
constraints. This class can be used to cover that gap. This validator does not recurse on the properties
of the bean (for that, annotate those properties with @Valid
and rely on BeanValidator
per-property validation).
See ValidatingBean
for a simpler, non-JSR 303 alternative to this class.
This is a bean-level validator, so any Binder
using this validator will need access to an actual bean in order
to validate (e.g., via Binder.setBean()
, Binder.writeBean()
,
Binder.writeBeanIfValid()
, etc.), otherwise you'll get an IllegalStateException
with bean level validators have been configured but no bean is currently set.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionapply
(Object bean, ValueContext valueContext) void
setValidationGroups
(Class<?>[] groups) Configure an alternate set of validation group(s) which will get passed toValidator.validate()
.void
setValidatorFactory
(jakarta.validation.ValidatorFactory validatorFactory) Configure a customValidatorFactory
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.function.BiFunction
andThen
-
Field Details
-
beanType
Bean type.
-
-
Constructor Details
-
WholeBeanValidator
Constructor.- Parameters:
beanType
- bean type- Throws:
NullPointerException
- ifbeanType
is null
-
-
Method Details
-
setValidationGroups
Configure an alternate set of validation group(s) which will get passed toValidator.validate()
.The default is an empty array, i.e.,
Default
.- Parameters:
groups
- group(s) to validate, or null forDefault
-
setValidatorFactory
public void setValidatorFactory(jakarta.validation.ValidatorFactory validatorFactory) Configure a customValidatorFactory
.If this property is left unset, then the factory returned by
BeanValidator.getJavaxBeanValidatorFactory()
is used.- Parameters:
validatorFactory
- custom validation factory, or null for none
-
apply
- Specified by:
apply
in interfaceBiFunction<Object,
ValueContext, ValidationResult> - Specified by:
apply
in interfaceValidator<Object>
-