-1

yaml is very convenient because you are getting a nice deserialization from yaml to java but in my case I need to be able to obtain the property value at runtime. Is there a way to accomplish this as if you were using .properties file instead, for example, just by having the property key value?

appName: myAppName

Here I'd like to obtain myAppName value at runtime using the snakeyaml library.

Todor Kolev
  • 1,432
  • 1
  • 16
  • 33

1 Answers1

1

Yes yaml.load() basically returns a java object so you can simply cast it to the appropriate type and get what you need:

    Yaml yaml = new Yaml();
    String input = "{appName: myAppName, appVersion: myAppVerison}";
    Map yamlMap = (Map)yaml.load(input);
    assertEquals("myAppName", yamlMap.get("appName"));
Todor Kolev
  • 1,432
  • 1
  • 16
  • 33