I read a yaml file to a map in kotlin (Map<String, Any>) this yaml file contains a list of strings, eks:
...
myStrings:
- string1
- string2
- string3
...
I read the map as follows:
private fun readWithGson(jsonPath: String): Map<String, Any> {
val bufferedReader = BufferedReader(FileReader(jsonPath))
val gson = Gson()
@Suppress("UNCHECKED_CAST")
return gson.fromJson(bufferedReader, Map::class.java) as Map<String, Any>
}
When println(map), it contains:
...
myStrings=[string1,string2,string3]
...
How can get the array of strings?
map["myStrings"] as Array<String>
produces a java.lang.ClassCastException
.toTypedArray(). Usingasis for casting, not converting.JSONformat to parse ayamlfile.. Not sure how that even works but you'll likely need a yaml parser like snakeYAML