Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naturalwarren/97c108eb3b99e84ebfe96cd60b968746 to your computer and use it in GitHub Desktop.
Save naturalwarren/97c108eb3b99e84ebfe96cd60b968746 to your computer and use it in GitHub Desktop.
RAVE's generated validator code.
public final class RaveValidatorFactory_Generated_Validator extends BaseValidator {
RaveValidatorFactory_Generated_Validator() {
addSupportedClass(MyModel.class);
registerSelf();
}
@Override
protected void validateAs(@NonNull Object object, @NonNull Class<?> clazz, @NonNull ExclusionStrategy exclusionStrategy) throws InvalidModelException {
if (!clazz.isInstance(object)) {
throw new IllegalArgumentException(object.getClass().getCanonicalName() + "is not of type" + clazz.getCanonicalName());
}
if (clazz.equals(MyModel.class)) {
validateAs((MyModel) object, exclusionStrategy);
return;
}
throw new IllegalArgumentException(object.getClass().getCanonicalName() + " is not supported by validator " + this.getClass().getCanonicalName());
}
private void validateAs(MyModel object, ExclusionStrategy exclusionStrategy) throws InvalidModelException {
BaseValidator.ValidationContext context = getValidationContext(MyModel.class);
List<RaveError> raveErrors = null;
if (!setContextAndCheckshouldIgnoreMethod(MyModel.class, "getSomeString", exclusionStrategy, context)) {
raveErrors = mergeErrors(raveErrors, checkNullable(object.getSomeString(), false, context));
}
if (!setContextAndCheckshouldIgnoreMethod(MyModel.class, "customValidationLogic", exclusionStrategy, context)) {
raveErrors = mergeErrors(raveErrors, mustBeTrue(object.customValidationLogic(), context));
}
if (raveErrors != null && !raveErrors.isEmpty()) {
throw new InvalidModelException(raveErrors);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment