2019-11-17

Tamaya HOCON (Extension Module)

Tamaya HOCON is an extension module. Refer also to the extensions documentation for further details.

What functionality does this module provide?

Tamaya HOCON provides support for reading configuration using Human Optimized Configuration (HOCON) format as defined by Lightbend Typesafe Config:

{
  a : A
  b : B
  c {
    o: O
    p: P
  }
}

Hereby the hierarchical structure of the HOCON document will be mapped into an according PropertyValue tree structure. By default this structure can be mapped to flat key-value pairs of type String, e.g. the above will be mapped to

a=A
b=B
c.o=O
c.p=P

This extension implements the SPI defined by the tamaya.formats extension module.

Compatibility

The module is based on Java 8.

Installation

To use the HOCON extension module you only must add the corresponding dependency to your module:

<dependency>
  <groupId>org.apache.tamaya.ext</groupId>
  <artifactId>tamaya-hocon</artifactId>
  <version>0.5-incubating-SNAPSHOT</version>
</dependency>

This extension also transitively requires the tamaya.formats module.

Reading configuration in HOCON

For reading HOCON based onfiguration most easily a HOCONFormat can be used:

ConfigurationData dataRead = ConfigurationFormats.getInstance().readConfig(
    getClassLoader().getResource("myFileConfig.hocon"), new HOCONFormat()));

Or, if you are fine with the default mapping you can directly create a PropertySource using the formats API (this works since this module registers the hocon format automatically in the ServiceContext):

PropertySource ps = ConfigurationFormats.getInstance().createPropertySource(
    getClassLoader().getResource("myFileConfig.hocon"));