Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Custom validator
package sample;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
public class SampleValidator implements ConstraintValidator<SampleValidation, String> {
private String param;
@Override
public void initialize(SampleValidation constraintAnnotation) {
this.param = constraintAnnotation.param();
System.out.println("@initialize : param=" + param + ", hashCode=" + hashCode());
}
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
System.out.println("@isValid : param=" + param + ", hashCode=" + hashCode() + ", value=" + value);
if (value == null) {
return true;
}
return !"".equals(value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment