I'm experimenting with the custom validator annotation with spring boot in my rest application.
here is the sample code from the validator, other requisite classes are present:
public class CustomerValidator implements ConstraintValidator<CustomerValidation, Customer>
{
public boolean isValid(Customer value, ConstraintValidatorContext cxt) {
if(value.getItemList.size() == 0) {
throw new CustomerOrderException();
}
if(value.getBalance() < value.getCost()) {
throw new InsufficientBalanceException();
}
return true;
}
}
I made a class annotated with controller advice and exception handler but it doesn't seem to intercept the exception thrown from the validator.