Package io.mailtrap

Class CustomValidator

java.lang.Object
io.mailtrap.CustomValidator

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

    • CustomValidator

      public CustomValidator(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