Created
February 21, 2017 10:41
-
-
Save kntmr/dfb2dcbf35c20ba662dfb8597b34dd9e to your computer and use it in GitHub Desktop.
Custom 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
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