Skip to content

Commit

Permalink
Set FAIL_ON_UNKNOWN_PROPERTIES in DefaultConfigurationFactoryFactory
Browse files Browse the repository at this point in the history
The logic is moved to DefaultConfigurationFactoryFactory from
YamlConfigurationFactory, making it easier to modify with a
custom ConfigurationFactoryFactory implementation.

There are some (uncommon) use cases where it's benefitial to
update an application without modifying the configuration, which
may fail if the application configuration has removed a configuration
property.
  • Loading branch information
carterkozak committed Aug 6, 2016
1 parent ab8eb67 commit a3bbd17
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.dropwizard.configuration;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.validation.Validator;
Expand All @@ -11,6 +12,11 @@ public ConfigurationFactory<T> create(
Validator validator,
ObjectMapper objectMapper,
String propertyPrefix) {
return new YamlConfigurationFactory<>(klass, validator, objectMapper, propertyPrefix);
return new YamlConfigurationFactory<>(
klass,
validator,
objectMapper.copy()
.enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES),
propertyPrefix);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.dropwizard.configuration;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -21,7 +20,6 @@
import javax.validation.Validator;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -69,8 +67,7 @@ public YamlConfigurationFactory(Class<T> klass,
mapper = null;
yamlFactory = null;
} else {
mapper = objectMapper.copy()
.enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper = objectMapper;
yamlFactory = new YAMLFactory();
}
this.validator = validator;
Expand Down

0 comments on commit a3bbd17

Please sign in to comment.