2017-11-25

Tamaya JSON (Extension Module)

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

What functionality this module provides ?

Tamaya JSON provides support for reading configuration using JSON format:

{
  "a.b"{
    "key1": "blabla",
    "key2": true,
  }
}

Hereby the hierarchical structure of the JSON document will be mapped to a flat key-value pairs of type String, e.g. the bove will be mapped to

a.b.key1=blabla
a.b.key2=true

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

Compatibility

The module is based on Java 7, so it will run on Java 7 and beyond.

Installation

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

<dependency>
  <groupId>org.apache.tamaya.ext</groupId>
  <artifactId>tamaya-json</artifactId>
  <version>{tamaya_version}</version>
</dependency>

This extension also transitively requires the tamaya.formats module.

Reading configuration in JSON

For reading JSON based onfiguration most easily a JSONFormat can be used:

ConfigurationData dataRead = ConfigurationFormats.readConfig(
    getClassLoader().getResource("myFileConfig.json"), new JSONFormat()));

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 json format automatically using the ServiceContext):

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