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 final com.fasterxml.jackson.databind.ObjectMapper
    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

    Modifier and Type
    Method
    Description
    protected void
    addOverride(com.fasterxml.jackson.databind.JsonNode root, String name, String value)
    Applies an override to a given JsonNode.
    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 given JsonNode.
    Loads, parses, binds, and validates a configuration object.
    protected com.fasterxml.jackson.core.JsonParser
    Constructs a JsonParser to parse the contents of the provided InputStream.

    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
  • Field Details

    • mapper

      protected final com.fasterxml.jackson.databind.ObjectMapper mapper
      The 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 used
      formatName - the name of the format parsed by this factory (used in exceptions)
      klass - the configuration class
      validator - the validator to use
      objectMapper - the object mapper to use
      propertyPrefix - 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: ConfigurationFactory
      Loads, parses, binds, and validates a configuration object.
      Specified by:
      build in interface ConfigurationFactory<T>
      Parameters:
      provider - the provider to use for reading configuration files
      path - the path of the configuration file
      Returns:
      a validated configuration object
      Throws:
      IOException - if there is an error reading the file
      ConfigurationException - if there is an error parsing or validating the file
    • createParser

      protected com.fasterxml.jackson.core.JsonParser createParser(InputStream input) throws IOException
      Constructs a JsonParser to parse the contents of the provided InputStream.
      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 interface ConfigurationFactory<T>
      Returns:
      a validated configuration object
      Throws:
      IOException - if there is an error reading the file
      ConfigurationException - 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 given JsonNode.
      Parameters:
      node - the json node to parse the configuration from
      path - the path of the configuration file
      Returns:
      a validated configuration object
      Throws:
      IOException - if there is an error reading the file
      ConfigurationException - if there is an error parsing or validating the file
    • addOverride

      protected void addOverride(com.fasterxml.jackson.databind.JsonNode root, String name, String value)
      Applies an override to a given JsonNode.
      Parameters:
      root - the node to apply the override to
      name - the key of the override
      value - the new value