Package io.dropwizard.configuration
Class BaseConfigurationFactory<T>
java.lang.Object
io.dropwizard.configuration.BaseConfigurationFactory<T>
- Type Parameters:
T- the type of the configuration objects to produce
- All Implemented Interfaces:
ConfigurationFactory<T>
- Direct Known Subclasses:
JsonConfigurationFactory,YamlConfigurationFactory
A generic factory class for loading configuration files, binding them to configuration objects, and
validating their constraints. Allows for overriding configuration parameters from system properties.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final com.fasterxml.jackson.databind.ObjectMapperThe object mapper to use for mapping configuration files to objects. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBaseConfigurationFactory(com.fasterxml.jackson.core.JsonFactory parserFactory, String formatName, Class<T> klass, @Nullable jakarta.validation.Validator validator, com.fasterxml.jackson.databind.ObjectMapper objectMapper, String propertyPrefix) Creates a new configuration factory for the given class. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddOverride(com.fasterxml.jackson.databind.JsonNode root, String name, String value) Applies an override to a givenJsonNode.build()Loads, parses, binds, and validates a configuration object from an empty document.protected TLoads, parses, binds, and validates a configuration object for a givenJsonNode.build(ConfigurationSourceProvider provider, String path) Loads, parses, binds, and validates a configuration object.protected com.fasterxml.jackson.core.JsonParsercreateParser(InputStream input) Constructs aJsonParserto parse the contents of the providedInputStream.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.dropwizard.configuration.ConfigurationFactory
build
-
Field Details
-
mapper
protected final com.fasterxml.jackson.databind.ObjectMapper mapperThe object mapper to use for mapping configuration files to objects.
-
-
Constructor Details
-
BaseConfigurationFactory
protected BaseConfigurationFactory(com.fasterxml.jackson.core.JsonFactory parserFactory, String formatName, Class<T> klass, @Nullable jakarta.validation.Validator validator, com.fasterxml.jackson.databind.ObjectMapper objectMapper, String propertyPrefix) Creates a new configuration factory for the given class.- Parameters:
parserFactory- the factory that creates the parser usedformatName- the name of the format parsed by this factory (used in exceptions)klass- the configuration classvalidator- the validator to useobjectMapper- the object mapper to usepropertyPrefix- the system property name prefix used by overrides
-
-
Method Details
-
build
public T build(ConfigurationSourceProvider provider, String path) throws IOException, ConfigurationException Description copied from interface:ConfigurationFactoryLoads, parses, binds, and validates a configuration object.- Specified by:
buildin interfaceConfigurationFactory<T>- Parameters:
provider- the provider to use for reading configuration filespath- the path of the configuration file- Returns:
- a validated configuration object
- Throws:
IOException- if there is an error reading the fileConfigurationException- if there is an error parsing or validating the file
-
createParser
Constructs aJsonParserto parse the contents of the providedInputStream.- Parameters:
input- the input to parse- Returns:
- the JSON parser for the given input
- Throws:
IOException- if the parser creation fails due to an I/O error
-
build
Description copied from interface:ConfigurationFactoryLoads, parses, binds, and validates a configuration object from an empty document.- Specified by:
buildin interfaceConfigurationFactory<T>- Returns:
- a validated configuration object
- Throws:
IOException- if there is an error reading the fileConfigurationException- if there is an error parsing or validating the file
-
build
protected T build(com.fasterxml.jackson.databind.JsonNode node, String path) throws IOException, ConfigurationException Loads, parses, binds, and validates a configuration object for a givenJsonNode.- Parameters:
node- the json node to parse the configuration frompath- the path of the configuration file- Returns:
- a validated configuration object
- Throws:
IOException- if there is an error reading the fileConfigurationException- if there is an error parsing or validating the file
-
addOverride
Applies an override to a givenJsonNode.- Parameters:
root- the node to apply the override toname- the key of the overridevalue- the new value
-