Class ValidationResult


  • public class ValidationResult
    extends Object
    Stores validation errors for a specific object.

    This class is heavily inspired on Spring's Errors interface. The main difference is that Hawaii's ValidationResult does not bind or require the target object being validated.

    Since:
    2.0.0
    Author:
    Marcel Overdijk, Rutger Lubbers
    • Field Detail

      • NESTED_PATH_SEPARATOR

        public static final String NESTED_PATH_SEPARATOR
        The separator between path elements in a nested path, for example in "name" or "address.street".
        See Also:
        Constant Field Values
    • Constructor Detail

      • ValidationResult

        public ValidationResult()
    • Method Detail

      • getNestedPath

        public String getNestedPath()
        Returns the current nested path of this ValidationResult.
        Returns:
        the current nested path
      • pushNestedPath

        public void pushNestedPath​(String path)
      • pushNestedPath

        public void pushNestedPath​(String path,
                                   int index)
      • hasErrors

        public boolean hasErrors()
        Returns true if this validation result contains errors.
        Returns:
        true if this validation result contains errors
      • getErrors

        public List<ValidationError> getErrors()
        Returns the validation errors.
        Returns:
        the validation errors
      • reject

        public void reject​(String code)
      • rejectIf

        public void rejectIf​(boolean expr,
                             String code)
      • rejectIf

        public <T> void rejectIf​(T actual,
                                 Matcher<? super T> matcher,
                                 String code)
      • rejectValue

        public void rejectValue​(String code)
      • rejectValue

        public void rejectValue​(String field,
                                String code)
      • rejectValueIf

        public void rejectValueIf​(boolean expr,
                                  String code)
      • rejectValueIf

        public <T> void rejectValueIf​(T actual,
                                      Matcher<? super T> matcher,
                                      String code)
      • rejectValueIf

        public void rejectValueIf​(boolean expr,
                                  String field,
                                  String code)
      • rejectValueIf

        public <T> void rejectValueIf​(T actual,
                                      Matcher<? super T> matcher,
                                      String field,
                                      String code)
      • rejectField

        public <T> FieldRejection<T> rejectField​(String field,
                                                 T actual)
        Reject a field with value actual in a fluent manner.

        For instance:

         validationResult.rejectField("houseNumber", "13-a")
                 .whenNull()
                 .orWhen(containsString("a"))
                 .orWhen(h -> h.length() > 4);
         
        Type Parameters:
        T - The type of the value.
        Parameters:
        field - The field name to evaluate.
        actual - The value to evaluate.
        Returns:
        a new field rejection.