I wanna create generic method for convert json string to List of objects.
fun convertJsonStringToObjectList(jsonString: String , clazz: Class<Any>) :List<Any>{
val gson = Gson()
val objectList = gson.fromJson(jsonString, Array<clazz>::class.java).asList()
return objectList
}
This code does not works. I know how to convert json string to a class like this:
fun <T> convertJsonStringToObject(jsonString: String, clazz: Class<T>): T {
val gson = Gson()
val objectList = gson.fromJson(jsonString, clazz)
return objectList
}
The problem is i wan to get class type from method and then add Array type to it and get classtype again. I do not know how to handle this.