Skip to content

Instantly share code, notes, and snippets.

@stella6767
Last active July 26, 2022 15:07
Show Gist options
  • Save stella6767/3778d828a62c8cddd7b5d4da81f50008 to your computer and use it in GitHub Desktop.
Save stella6767/3778d828a62c8cddd7b5d4da81f50008 to your computer and use it in GitHub Desktop.
json object Array file reader
fun <T> readJsonArrayFile(filePath: String): List<Map<*, *>?>? {
val mapper = ObjectMapper()
//val readFileAsString = readFileAsString(filePath)
//println(readFileAsString)
val myObjects = mapper.readValue(File(filePath), object : TypeReference<List<Map<*, *>?>>() {})
// for (obj in myObjects) {
// println(obj)
// }
return myObjects
}
private fun readFileAsString(filePath: String): String {
return String(Files.readAllBytes(Paths.get(filePath)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment