I am using snakeYaml to parse certain configuration/property values to a Configuration object.
My yaml file looks like this -
#Thread
batchLimit: 1000
th
Yaml file "AppParams.yml" with key-value pairs:
someConfig:
key1: value1
key2: value2
POJO:
public class ApplicationParameters {
private Map someConfig;
public ApplicationParameters() {
}
public Map getSomeConfig() {
return someConfig;
}
public void setSomeConfig(Map someConfig) {
this.someConfig = someConfig;
}
}
Reader:
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
File paramFile = new File("AppParams.yml");
ApplicationParameters applicationParameters = mapper.readValue(paramFile, ApplicationParameters.class);
Map someConfig = applicationParameters.getSomeConfig();
String key1Value = someConfig.get("key1"); //returns "value1"
The example above uses these dependencies in POM.xml:
com.fasterxml.jackson.core
jackson-core
2.9.8
com.fasterxml.jackson.core
jackson-databind
2.9.8
com.fasterxml.jackson.dataformat
jackson-dataformat-yaml
2.9.8