Created
May 6, 2023 18:36
-
-
Save zencd/651561a7bc3e28ea3c9b6a61ee5ac6ec to your computer and use it in GitHub Desktop.
Pojo Validator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static final Validator VALIDATOR = Validation.buildDefaultValidatorFactory().getValidator() | |
static void validatePojo(Object pojo) { | |
def errors = VALIDATOR.validate(pojo); | |
if (errors.size() > 0) { | |
log.error("Validation errors for {}: {}", pojo.getClass().getSimpleName(), errors); | |
throw new RuntimeException("Pojo validation failed - see logs - " + pojo.getClass().getName()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment