I am missing a basic validator that allows a property to be optional (null is valid) but if its value is set it must not be an empty String (trimmed).
In my opinion this is some of the most used cases. I dont want my optional columns to be possible cluttered with empty Strings.
Basically this simple validator:
public class NullOrNotBlankValidator implements ConstraintValidator<NullOrNotBlank, String> { @Override public void initialize(final NullOrNotBlank constraintAnnotation){}
@Override public boolean isValid(final String value, final ConstraintValidatorContext context) { return value == null || !value.trim().isEmpty(); }
}
|