I have a nested YAML file as below and I want to process it in scala with snakeyaml.Yaml however I encounter an error: Unable to find property 'myMap' on class MyConfig
Here is an example of the Yaml file that I have:
myMap:
-
name: key1
value: value1
-
name: key2
value: value2
I defined two classes for the YAML structure. I am using org.yaml.snakeyaml.Yaml to do yaml.load
class ConfigParamsKeyValue {
@BeanProperty var name: String = null
@BeanProperty var value: String = null
}
class MyConfig{
@BeanProperty var myMap= new java.util.ArrayList[ConfigParamsKeyValue]();
}
def loadConfig(filename : String): MyConfig = {
val yaml = new Yaml(new Constructor(classOf[MyConfig]))
val stream = new FileInputStream(filename)
try {
val obj = yaml.load(stream)
obj.asInstanceOf[MyConfig]
} finally {
stream.close()
}
}