Pincode validator class
public class PincodeValidator implements ConstraintValidator { int size;
@Override
public void initialize(IsValidPincode constraintAnnotation) {
this.size = constraintAnnotation.sizeOfPincode();
}
@Override
public boolean isValid(Integer num, ConstraintValidatorContext arg1) {
if(num==null)return false;
if(Math.floor(Math.log10(num) + 1)==size) return true;
return false;
}}
Student Bean column :
@IsValidPincode(sizeOfPincode=6, message="Pincode must be of size {sizeOfPincode}")
@Column(name="pincode")
int pincode;
Error given by BinderResult:
Failed to convert property value of type java.lang.String to required type int for property pincode; nested exception is java.lang.NumberFormatException: For input string: ""
what i am asking is, how to handle that binderresult error my custom error that : Pincode cannot be empty