Interface ConfigMapperProvider

All Known Implementing Classes:
ObjectConfigMapperProvider
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface @Contract public interface ConfigMapperProvider
Provides mapping functions that convert a Config subtree to specific Java types.

The config system automatically loads ConfigMapperProviders using the Java ServiceLoader mechanism, and by default the config system automatically registers all ConfigMappers from all such providers with every Config.Builder. The application can suppress auto-registration of loaded mappers by invoking Config.Builder.disableMapperServices().

Each ConfigMapperProvider can specify a Weight. The default weight is 100.0.

See Also:
  • Method Details

    • mappers

      Map<Class<?>,Function<Config,?>> mappers()
      Returns a map of mapper functions associated with appropriate target type (Class<?>.

      Mappers will be automatically registered by Config.Builder during bootstrapping of Config unless disableld.

      Returns:
      a map of config mapper functions, never null, though this may return an empty map if mapper(Class) is used instead
    • genericTypeMappers

      default Map<GenericType<?>,BiFunction<Config,ConfigMapper,?>> genericTypeMappers()
      Returns a map of mapper functions associated with appropriate target type (GenericType<?>.

      Mappers will be automatically registered by Config.Builder during bootstrapping of Config unless disableld.

      Returns:
      a map of config mapper functions, never null, though this may return an empty map if mapper(Class) is used instead
    • mapper

      default <T> Optional<Function<Config,T>> mapper(Class<T> type)
      A simple mapping function from config node to a typed value based on the expected class. If more complex type handling or conversion is needed, use mapper(GenericType).
      Type Parameters:
      T - type returned from conversion
      Parameters:
      type - type of the expected mapping result
      Returns:
      function to convert config node to the expected type, or empty if the type is not supported by this provider
    • mapper

      default <T> Optional<BiFunction<Config,ConfigMapper,T>> mapper(GenericType<T> type)
      Mapper for a specific generic type. If your mapper only supports simple classes, get it using GenericType.rawType(). Otherwise, you have access to the (possibly) generics type of the expected result using GenericType.type().

      The mapping function has two parameters:

      • Config - config node to convert to the expected type
      • ConfigMapper - mapper to help with conversion of sub-nodes if needed
      and returns a typed value.
      Type Parameters:
      T - type to map to
      Parameters:
      type - type providing information what is the mapped type
      Returns:
      a function that would convert the provided Config instance into the expected type if supported by this provider, empty otherwise.