diff --git a/src/main/java/com/github/joschi/jadconfig/JadConfig.java b/src/main/java/com/github/joschi/jadconfig/JadConfig.java index 54ca7ff..9678978 100644 --- a/src/main/java/com/github/joschi/jadconfig/JadConfig.java +++ b/src/main/java/com/github/joschi/jadconfig/JadConfig.java @@ -186,12 +186,9 @@ private void processClassField(Object configurationBean, Field field) throws Val } catch (ParameterException e) { throw new ParameterException("Couldn't convert value for parameter \"" + parameterName + "\"", e); } - - LOG.debug("Validating parameter {}", parameterName); - final List>> validators = - new ArrayList<>(Collections.>>singleton(parameter.validator())); - validators.addAll(Arrays.asList(parameter.validators())); - validateParameter(validators, parameterName, fieldValue); + validateFieldValue(parameterName, parameter, fieldValue); + } else if (fieldValue != null) { + validateFieldValue(parameterName, parameter, fieldValue); } LOG.debug("Setting parameter {} to {}", parameterName, fieldValue); @@ -204,6 +201,14 @@ private void processClassField(Object configurationBean, Field field) throws Val } } + private void validateFieldValue(String parameterName, Parameter parameter, Object fieldValue) throws ValidationException { + LOG.debug("Validating parameter {}", parameterName); + final List>> validators = + new ArrayList<>(Collections.>>singleton(parameter.validator())); + validators.addAll(Arrays.asList(parameter.validators())); + validateParameter(validators, parameterName, fieldValue); + } + private String lookupFallbackParameter(Parameter parameter) { final Optional fallbackValue = Optional.ofNullable(parameter.fallbackPropertyName()) .filter(fallbackName -> !fallbackName.trim().isEmpty())