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
public abstract class BaseConfigurationFactory<T> extends Object implements ConfigurationFactory<T>
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
Fields Modifier and Type Field Description protected com.fasterxml.jackson.databind.ObjectMapper
mapper
The object mapper to use for mapping configuration files to objects.
-
Constructor Summary
Constructors Modifier Constructor Description 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addOverride(com.fasterxml.jackson.databind.JsonNode root, String name, String value)
Applies an override to a givenJsonNode
.T
build()
Loads, parses, binds, and validates a configuration object from an empty document.protected T
build(com.fasterxml.jackson.databind.JsonNode node, String path)
Loads, parses, binds, and validates a configuration object for a givenJsonNode
.T
build(ConfigurationSourceProvider provider, String path)
Loads, parses, binds, and validates a configuration object.protected com.fasterxml.jackson.core.JsonParser
createParser(InputStream input)
Constructs aJsonParser
to parse the contents of the providedInputStream
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.dropwizard.configuration.ConfigurationFactory
build
-
-
-
-
Constructor Detail
-
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 Detail
-
build
public T build(ConfigurationSourceProvider provider, String path) throws IOException, ConfigurationException
Description copied from interface:ConfigurationFactory
Loads, parses, binds, and validates a configuration object.- Specified by:
build
in interfaceConfigurationFactory<T>
- Parameters:
provider
- the provider to 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
protected com.fasterxml.jackson.core.JsonParser createParser(InputStream input) throws IOException
Constructs aJsonParser
to 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
public T build() throws IOException, ConfigurationException
Description copied from interface:ConfigurationFactory
Loads, parses, binds, and validates a configuration object from an empty document.- Specified by:
build
in 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
-
-