Skip to content

Instantly share code, notes, and snippets.

@zencd
Created May 6, 2023 18:36
Show Gist options
  • Save zencd/651561a7bc3e28ea3c9b6a61ee5ac6ec to your computer and use it in GitHub Desktop.
Save zencd/651561a7bc3e28ea3c9b6a61ee5ac6ec to your computer and use it in GitHub Desktop.
Pojo Validator
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