Let say I have a config file with the following:
someConfig: [
{"t1" :
[ {"t11" : "v11",
"t12" : "v12",
"t13" : "v13",
"t14" : "v14",
"t15" : "v15"},
{"t21" : "v21",
"t22" : "v22",
"t23" : "v13",
"t24" : "v14",
"t25" : "v15"}]
},
"p1" :
[ {"p11" : "k11",
"p12" : "k12",
"p13" : "k13",
"p14" : "k14",
"p15" : "k15"},
{"p21" : "k21",
"p22" : "k22",
"p23" : "k13",
"p24" : "k14",
"p25" : "k15"}]
}
]
I would like to retrieve it as a Scala immutable collection Map[List[Map[String, String]]].
using the following code I am only able to retrieve it as a List of HashMaps (more precisely a $colon$colon of HashMap) which fails when I try to iterate trough it. Ideally to complete my code I need a way to convert the HashMap to scala maps
def example: Map[String, List[Map[String,String]]] = {
val tmp = ConfigFactory.load("filename.conf")
val mylist : Iterable[ConfigObject] = tmp.getObjectList("someConfig")
.asScala
(for {
item : ConfigObject <- mylist
myEntry: Entry[String, ConfigValue] <- item.entrySet().asScala
name = entry.getKey
value = entry.getValue.unwrapped()
.asInstanceOf[util.ArrayList[Map[String,String]]]
.asScala.toList
} yield (name, value)).toMap
}