Package io.mailtrap

Class MailtrapValidator

java.lang.Object
io.mailtrap.MailtrapValidator

public class MailtrapValidator extends Object
Wrapper for validating objects using a javax.validation.Validator.
  • Constructor Details

    • MailtrapValidator

      public MailtrapValidator(jakarta.validation.Validator validator)
  • Method Details

    • validate

      public <T> Map<String,String> validate(T objectToValidate)
      Validates the given object and returns a map of validation errors.

      The map contains property names as keys and corresponding error messages as values. If the object has no validation errors, the map will be empty.

      Type Parameters:
      T - the type of the object to validate
      Parameters:
      objectToValidate - the object to validate
      Returns:
      a map of validation errors, with property names as keys and error messages as values
    • validateAndGetViolationsAsString

      public <T> String validateAndGetViolationsAsString(T objectToValidate)
      Validates the given object and returns a string representation of the validation errors.

      The returned string contains each validation error in the format "propertyName=errorMessage", with errors separated by semicolons. If there are no validation errors, an empty string is returned.

      Type Parameters:
      T - the type of the object to validate
      Parameters:
      objectToValidate - the object to validate
      Returns:
      a string representation of the validation errors, or an empty string if there are no errors