public interface Validator
Validate plain Java objects that have been annotated with validation constraints.
// create a validator
final Validator validator = Validator.builder()
.setDefaultLocale(Locale.CANADA)
.addLocales(Locale.GERMAN)
.build();
// validate a pojo
Customer customer = ...;
validator.validate(customer);
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceFunction to build a ValidationAdapter from a Validation Contextstatic interfaceFunction to build a ValidationAdapter that needs Validator.static interfaceBuild the Validator instance adding ValidationAdapter, Factory or AdapterBuilder.static interfaceComponents register ValidationAdapters Validator.Builder -
Method Summary
Modifier and TypeMethodDescriptionstatic Validator.Builderbuilder()Return the Builder used to build the Validator.context()Return the validation context used to create adaptersvoidValidate the object using the default locale.voidValidate the object with a given locale.
-
Method Details
-
validate
Validate the object using the default locale.- Throws:
ConstraintViolationException
-
validate
void validate(Object any, @Nullable Locale locale, @Nullable Class<?>... groups) throws ConstraintViolationException Validate the object with a given locale.If the locale is not one of the supported locales then the default locale will be used.
This is expected to be used when the Validator is configured to support multiple locales.
- Throws:
ConstraintViolationException
-
context
ValidationContext context()Return the validation context used to create adapters -
builder
Return the Builder used to build the Validator.final Validator validator = Validator.builder() .setDefaultLocale(Locale.CANADA) .addLocales(Locale.GERMAN) .build();
-