Package uk.ac.ebi.utils.opt.config
Class YAMLLoader
java.lang.Object
uk.ac.ebi.utils.opt.config.YAMLLoader
A simple YAML document/file loader, which is focused on configuration needs.
The basic function of this component is loading YAML files and mapping them to POJO classes.
It also offers features that are often useful when dealing with application configurations:
TODO: support for URLs
TODO: Support Spring SpEL for interpolation.
TODO: support for charsets?
- It allows for inclusions, using the
INCLUDES_FIELD
at the YAML document/file root level (ie, not in a nested level. Optional inclusions are also supported, viaINCLUDES_OPTIONAL_FIELD
. - When including a file from a parent, you can extend (instead of override) fields that the parent defined
as arrays or objects. Append
MERGE_SUFFIX
to the field and it's values will be added to the field with the same name (minus the postfix). For instance, if a parent file has:options: [default]
and an included file hasoptions @merge: [advanced]
, the result for options will be [default, advanced]. When mapping to JavaBean properties of type collection, the collection is populated with the merge result (and properties like order or repetitions depend on the exact collection type used for the JavaBean). - Property interpolation: When using ${propName} in YAML values (not field names), the referred
property replaced with values in the
JVM properties
, orenvironment variables
, or even properties defined viaPROPDEF_FIELD
. This is based onSpring
TODO: support for URLs
TODO: Support Spring SpEL for interpolation.
TODO: support for charsets?
- Author:
- brandizi
- Date:
- 14 Jun 2022
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
A property with this name is always available and contains the dir in which the YAML file isstatic final String
A property with this name is always available and contains the absolute YAML file pathstatic final String
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
loadYAMLFromFile
(String filePath, Class<T> targetClass) static <T> T
loadYAMLFromString
(String yamlStr, Class<T> targetClass) Maps a YAML file to a target, after it has been processes as explained above.
-
Field Details
-
INCLUDES_FIELD
- See Also:
-
INCLUDES_OPTIONAL_FIELD
- See Also:
-
MERGE_SUFFIX
- See Also:
-
PROPDEF_FIELD
- See Also:
-
MY_PATH_PROP
A property with this name is always available and contains the absolute YAML file path- See Also:
-
MY_DIR_PROP
A property with this name is always available and contains the dir in which the YAML file is- See Also:
-
-
Constructor Details
-
YAMLLoader
public YAMLLoader()
-
-
Method Details
-
loadYAMLFromFile
public static <T> T loadYAMLFromFile(String filePath, Class<T> targetClass) throws UncheckedIOException - Throws:
UncheckedIOException
-
loadYAMLFromString
Maps a YAML file to a target, after it has been processes as explained above.
-