我有一个嵌套的YAML文件,如下所示,我想使用snakeyaml.Yaml在scala中对其进行处理,但是遇到错误: 在类MyConfig上找不到属性“ myMap”
以下是我拥有的Yaml文件的示例:
myMap:
-
name: key1
value: value1
-
name: key2
value: value2
我为YAML结构定义了两个类。我正在使用org.yaml.snakeyaml.Yaml做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()
}
}