Class 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 on ValidationErrors, see https://developer.paypal.com/braintree/docs/reference/general/validation-errors/overview/java
    • Constructor Detail

      • ValidationErrors

        public ValidationErrors()
      • ValidationErrors

        public ValidationErrors​(NodeWrapper node)
    • Method Detail

      • deepSize

        public int deepSize()
        Returns the number of errors on this object and all nested objects.
        Returns:
        the number of errors.
        See Also:
        size()
      • forObject

        public ValidationErrors forObject​(String objectName)
        Returns a ValidationErrors representing nested errors for the given objectName.
        Parameters:
        objectName - the name of the object with nested validation errors, e.g. customer or creditCard.
        Returns:
        a ValidationErrors object.
      • 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()