java.lang.Object
io.helidon.config.EnumMapperProvider
- All Implemented Interfaces:
ConfigMapperProvider
Built-in mapper for
enums.
This mapper attempts to match strings in the config source to enum values as follows:
- The mapper treats hyphens ('-') in config strings as underscores when comparing to enum value names.
- If the matcher finds a case-sensitive match with an enum value name, then that enum value matches.
- If the matcher finds exactly one case-insensitive match, that enum value matches.
- If the matcher finds no matches or multiple matches, throw a
ConfigMappingExceptionwith a message explaining the problem.
The only hardship this imposes is if a confusingly-designed enum has values which differ only in case and the
string in the config source does not exactly match one of the enum value names. In such cases
the mapper will be unable to choose which enum value matches an ambiguous string. A developer faced with this
problem can simply provide her own explicit config mapping for that enum, for instance as a function parameter to
Config#as.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionA simple mapping function from config node to a typed value based on the expected class.mappers()Returns a map of mapper functions associated with appropriate target type (Class<?>.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.helidon.config.spi.ConfigMapperProvider
genericTypeMappers, mapper
-
Constructor Details
-
EnumMapperProvider
public EnumMapperProvider()Required constructor forServiceLoader.
-
-
Method Details
-
mappers
Description copied from interface:ConfigMapperProviderReturns a map of mapper functions associated with appropriate target type (Class<?>.Mappers will be automatically registered by
Config.Builderduring bootstrapping ofConfigunlessdisableld.- Specified by:
mappersin interfaceConfigMapperProvider- Returns:
- a map of config mapper functions, never
null, though this may return an empty map ifConfigMapperProvider.mapper(Class)is used instead
-
mapper
Description copied from interface:ConfigMapperProviderA simple mapping function from config node to a typed value based on the expected class. If more complex type handling or conversion is needed, useConfigMapperProvider.mapper(GenericType).- Specified by:
mapperin interfaceConfigMapperProvider- 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
-