Class EnumMapperProvider

java.lang.Object
io.helidon.config.EnumMapperProvider
All Implemented Interfaces:
ConfigMapperProvider

public class EnumMapperProvider extends Object implements 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 ConfigMappingException with a message explaining the problem.
These conversions are intended to maximize ease-of-use for authors of config sources so the values need not be upper-cased nor punctuated with underscores rather than the more conventional (in config at least) hyphen.

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.