public class ValidationResult extends Object
This class is heavily inspired on Spring's org.springframework.validation.Errors
interface. The main difference is that Hawaii's
ValidationResult
does not bind or require the target object being validated.
Modifier and Type | Field and Description |
---|---|
static String |
NESTED_PATH_INDEX_PREFIX |
static String |
NESTED_PATH_INDEX_SUFFIX |
static String |
NESTED_PATH_SEPARATOR
The separator between path elements in a nested path, for example in "name" or "address.street".
|
Constructor and Description |
---|
ValidationResult() |
Modifier and Type | Method and Description |
---|---|
void |
addAllErrors(List<ValidationError> errors)
Adds the supplied
ValidationError s to this ValidationResult . |
void |
addAllErrors(ValidationResult validationResult)
Adds all errors from the supplied
ValidationResult to this ValidationResult . |
void |
addError(ValidationError error)
Adds the supplied
ValidationError to this ValidationResult . |
List<ValidationError> |
getErrors()
Returns the validation errors.
|
String |
getNestedPath()
Returns the current nested path of this
ValidationResult . |
boolean |
hasErrors()
Returns
true if this validation result contains errors. |
void |
popNestedPath() |
void |
pushNestedPath(String path) |
void |
pushNestedPath(String path,
int index) |
void |
reject(String code) |
<T> FieldRejection<T> |
rejectField(String field,
T actual)
Reject a
field with value actual in a fluent manner. |
void |
rejectIf(boolean expr,
String code) |
<T> void |
rejectIf(T actual,
Matcher<? super T> matcher,
String code) |
void |
rejectValue(String code) |
void |
rejectValue(String field,
String code) |
void |
rejectValueIf(boolean expr,
String code) |
void |
rejectValueIf(boolean expr,
String field,
String code) |
<T> void |
rejectValueIf(T actual,
Matcher<? super T> matcher,
String code) |
<T> void |
rejectValueIf(T actual,
Matcher<? super T> matcher,
String field,
String code) |
String |
toString() |
public static final String NESTED_PATH_SEPARATOR
public static final String NESTED_PATH_INDEX_PREFIX
public static final String NESTED_PATH_INDEX_SUFFIX
public String getNestedPath()
ValidationResult
.public void pushNestedPath(String path)
public void pushNestedPath(String path, int index)
public void popNestedPath() throws IllegalArgumentException
IllegalArgumentException
public boolean hasErrors()
true
if this validation result contains errors.true
if this validation result contains errorspublic List<ValidationError> getErrors()
public void reject(String code)
public void rejectIf(boolean expr, String code)
public void rejectValue(String code)
public void rejectValueIf(boolean expr, String code)
public <T> void rejectValueIf(T actual, Matcher<? super T> matcher, String field, String code)
public <T> FieldRejection<T> rejectField(String field, T actual)
field
with value actual
in a fluent manner.
For instance:
validationResult.rejectField("houseNumber", "13-a") .whenNull() .orWhen(containsString("a")) .orWhen(h -> h.length() > 4);
T
- The type of the value.field
- The field name to evaluate.actual
- The value to evaluate.public void addError(ValidationError error)
ValidationError
to this ValidationResult
.error
- the validation errorpublic void addAllErrors(List<ValidationError> errors)
ValidationError
s to this ValidationResult
.errors
- the validation errorspublic void addAllErrors(ValidationResult validationResult)
ValidationResult
to this ValidationResult
.validationResult
- the validation result to merge in