Skip to content

Using the API

Magnus Leßmann (aka. mark332) edited this page Jul 9, 2019 · 1 revision

The API offers interfaces for loaders (IConfigLoader), serializers (IConfigSerializer), configuration nodes (IConfigNode) and whole configuration (IConfig) abstractions.

Getting config loaders

Configuration loaders can be retrieved by the LoaderFactory using the #getLoader(String) method which takes file extensions or mime types as defined by the respective loaders @FormatRef annotation.
Configuration loaders can parse InputStreams into instances of IConfigNode.

Getting whole configurations

Instances of IConfig need to be constructed manually. As of now, the FileConfig is available for configurations loaded from java.io.File instances. It is recommended that the controlling part of an application takes care of instantiation of IConfig objects then passing them on to the consuming part of the code as IConfigs.

Using configuration nodes

Configurations will be deserialized into tree-like structures made of config nodes which are all IValueHolders and thus can carry different values. The value of a configuration node can be extracted using the different API methods on IConfigNode and its super interfaces. (Please see their javadoc comments in the sources jar artifact!)
A configuration node can be:

  • A map of String -> IConfigNode
  • A list of IConfigNode
  • A primitive value (Integer, Float, Double, Boolean)
  • A string
  • A virtual configuration node meaning that no value is stored and the node will not be serialized.

The tree below a configuration node can be traversed using the #getNode(String...) method which will always return a non-null configuration node that will be virtual should the path not exist in the configuration.

Clone this wiki locally