blob: 965211dbd1158f7137756ed9987f2ca24ee79629 [file] [log] [blame]
:jbake-type: page
:jbake-status: published
= Apache Tamaya - Extension: HJSON Format
toc::[]
[[HJSON]]
== Tamaya HJSON (Extension Module)
Tamaya _HJSON_ is an extension module. Refer also to the link:../extensions.html[extensions documentation] for further details.
=== What functionality does this module provide?
Tamaya _HJSON_ provides support for reading configuration in HJSON, a JSP similar format better
suited for humans:
[source, hjson]
-----------------------------------------------
{
a : A
b : {
o : O
p : P
}
c : C
}
-----------------------------------------------
Hereby the hierarchical structure of the JSON document will be mapped to a
corresponding `PropertyValue` tree structure. This structure can be mapped
to flat key-value pairs of type `String`, e.g. the above will be mapped to
[source, properties]
-----------------------------------------------
a=A
b.o=O
b.p=P
c=C
-----------------------------------------------
This extension implements the SPI defined by the +tamaya.formats+ extension module.
=== Compatibility
The module is based on Java 8.
=== Installation
To use the HJSON extension module you only must add the corresponding dependency to your project:
[source, xml, subs=attributes+]
-----------------------------------------------
<dependency>
<groupId>org.apache.tamaya.ext</groupId>
<artifactId>tamaya-hjson</artifactId>
<version>{tamaya_version}</version>
</dependency>
-----------------------------------------------
This extension also transitively requires the +tamaya.formats+ module.
=== Reading configuration in HJSON
For reading HJSON based configuration most easily a +HJSONFormat+ can be
used:
[source, java]
-----------------------------------------------
ConfigurationData dataRead = ConfigurationFormats.getInstance().readConfig(
getClassLoader().getResource("myFileConfig.json"), new HJSONFormat()));
-----------------------------------------------
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`):
[source, java]
-----------------------------------------------
PropertySource ps = ConfigurationFormats.getInstance().createPropertySource(
getClassLoader().getResource("myFileConfig.hjson"));
-----------------------------------------------