Skip to content

Instantly share code, notes, and snippets.

@hosseiniSeyRo
Created April 14, 2021 08:40
Show Gist options
  • Save hosseiniSeyRo/88638e9e8b26be0b7ea953e4b20b22fa to your computer and use it in GitHub Desktop.
Save hosseiniSeyRo/88638e9e8b26be0b7ea953e4b20b22fa to your computer and use it in GitHub Desktop.
Convert JsonString to Object
fun <T> convertJsonStringToObject(jsonString: String?, objectClass: Class<T>?): T {
return Gson().fromJson(jsonString, objectClass)
}
fun <T> convertJsonStringToObjectList(jsonString: String): List<T> {
return Gson().fromJson(jsonString, object : TypeToken<List<T?>?>() {}.type)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment