Package io.helidon.config.spi
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 public interface ConfigMapperProvider
Provides mapping functions that convert aConfig
subtree to specific Java types.The config system automatically loads
ConfigMapperProvider
s using the JavaServiceLoader
mechanism, and by default the config system automatically registers allConfigMapper
s from all such providers with everyConfig.Builder
. The application can suppress auto-registration of loaded mappers by invokingConfig.Builder.disableMapperServices()
.Each
ConfigMapperProvider
can specify aPriority
. The default priority is 100.
-
-
Field Summary
Fields Modifier and Type Field Description static int
PRIORITY
Default priority of the mapper provider if registered byConfig.Builder
automatically.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Map<GenericType<?>,BiFunction<Config,ConfigMapper,?>>
genericTypeMappers()
Returns a map of mapper functions associated with appropriate target type (GenericType<?>
.default <T> Optional<BiFunction<Config,ConfigMapper,T>>
mapper(GenericType<T> type)
Mapper for a specific generic type.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.Map<Class<?>,Function<Config,?>>
mappers()
Returns a map of mapper functions associated with appropriate target type (Class<?>
.
-
-
-
Field Detail
-
PRIORITY
static final int PRIORITY
Default priority of the mapper provider if registered byConfig.Builder
automatically.- See Also:
- Constant Field Values
-
-
Method Detail
-
mappers
Map<Class<?>,Function<Config,?>> mappers()
Returns a map of mapper functions associated with appropriate target type (Class<?>
.Mappers will by automatically registered by
Config.Builder
during bootstrapping ofConfig
unlessdisableld
.- Returns:
- a map of config mapper functions, never
null
, though this may return an empty map ifmapper(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 by automatically registered by
Config.Builder
during bootstrapping ofConfig
unlessdisableld
.- Returns:
- a map of config mapper functions, never
null
, though this may return an empty map ifmapper(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, usemapper(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 usingGenericType.rawType()
. Otherwise you have access to the (possibly) generics type of the expected result usingGenericType.type()
.The mapping function has two parameters:
Config
- config node to convert to the expected typeConfigMapper
- mapper to help with conversion of sub-nodes if needed
- 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.
-
-