Package com.braintreegateway
Class ValidationErrors
- java.lang.Object
-
- com.braintreegateway.ValidationErrors
-
public class ValidationErrors extends Object
Represents a collection of (nested) validation errors. Query for validation errors by object and field. For Example:TransactionRequest request = new TransactionRequest(). amount(null). Result<Transaction> result = gateway.transaction().sale(request); Assert.assertFalse(result.isSuccess()); ValidationErrors errors = result.getErrors(); Assert.assertEquals(ValidationErrorCode.TRANSACTION_AMOUNT_IS_REQUIRED, errors.forObject("transaction").onField("amount").get(0).getCode());For more detailed information onValidationErrors, see https://developer.paypal.com/braintree/docs/reference/general/validation-errors/overview/java
-
-
Field Summary
Fields Modifier and Type Field Description private List<ValidationError>errorsprivate Map<String,ValidationErrors>nestedErrors
-
Constructor Summary
Constructors Constructor Description ValidationErrors()ValidationErrors(NodeWrapper node)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddError(ValidationError error)voidaddErrors(String objectName, ValidationErrors errors)intdeepSize()Returns the number of errors on this object and all nested objects.ValidationErrorsforIndex(int index)ValidationErrorsforObject(String objectName)Returns aValidationErrorsrepresenting nested errors for the given objectName.List<ValidationError>getAllDeepValidationErrors()Returns a List of all of theValidationErroron this object and all nested objects.List<ValidationError>getAllValidationErrors()Returns a List of all of theValidationErrorobjects at the current nesting level.List<ValidationError>onField(String fieldName)Returns a List ofValidationErrorobjects for the given field.private voidpopulateErrors(NodeWrapper node)private voidpopulateTopLevelErrors(List<NodeWrapper> childErrors)intsize()Returns the number of errors on this object at the current nesting level.
-
-
-
Field Detail
-
errors
private List<ValidationError> errors
-
nestedErrors
private Map<String,ValidationErrors> nestedErrors
-
-
Constructor Detail
-
ValidationErrors
public ValidationErrors()
-
ValidationErrors
public ValidationErrors(NodeWrapper node)
-
-
Method Detail
-
addError
public void addError(ValidationError error)
-
addErrors
public void addErrors(String objectName, ValidationErrors errors)
-
deepSize
public int deepSize()
Returns the number of errors on this object and all nested objects.- Returns:
- the number of errors.
- See Also:
size()
-
forIndex
public ValidationErrors forIndex(int index)
-
forObject
public ValidationErrors forObject(String objectName)
Returns aValidationErrorsrepresenting nested errors for the given objectName.- Parameters:
objectName- the name of the object with nested validation errors, e.g. customer or creditCard.- Returns:
- a
ValidationErrorsobject.
-
getAllDeepValidationErrors
public List<ValidationError> getAllDeepValidationErrors()
Returns a List of all of theValidationErroron this object and all nested objects.- Returns:
- a List of
ValidationErrorobjects.
-
getAllValidationErrors
public List<ValidationError> getAllValidationErrors()
Returns a List of all of theValidationErrorobjects at the current nesting level.- Returns:
- a List of
ValidationErrorobjects.
-
onField
public List<ValidationError> onField(String fieldName)
Returns a List ofValidationErrorobjects for the given field.- Parameters:
fieldName- the name of the field with errors, e.g. amount or expirationDate.- Returns:
- a List of
ValidationErrorobjects
-
populateErrors
private void populateErrors(NodeWrapper node)
-
populateTopLevelErrors
private void populateTopLevelErrors(List<NodeWrapper> childErrors)
-
size
public int size()
Returns the number of errors on this object at the current nesting level.- Returns:
- the number of errors.
- See Also:
deepSize()
-
-