Interface Validator


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 Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Function to build a ValidationAdapter from a Validation Context
    static interface 
    Function to build a ValidationAdapter that needs Validator.
    static interface 
    Build the Validator instance adding ValidationAdapter, Factory or AdapterBuilder.
    static interface 
    Components register ValidationAdapters Validator.Builder
  • Method Summary

    Modifier and Type
    Method
    Description
    Return the Builder used to build the Validator.
    Return the validation context used to create adapters
    void
    validate(Object value, Class<?>... groups)
    Validate the object using the default locale.
    void
    validate(Object any, Locale locale, Class<?>... groups)
    Validate the object with a given locale.
  • Method Details

    • validate

      void validate(Object value, @Nullable Class<?>... groups) throws ConstraintViolationException
      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

      Return the validation context used to create adapters
    • builder

      static Validator.Builder builder()
      Return the Builder used to build the Validator.
      
      
         final Validator validator = Validator.builder()
           .setDefaultLocale(Locale.CANADA)
           .addLocales(Locale.GERMAN)
           .build();