Skip to content

Instantly share code, notes, and snippets.

@salihyalcin
Created April 28, 2020 11:03
Show Gist options
  • Save salihyalcin/74c860a39c5da9f054e01d858d17876b to your computer and use it in GitHub Desktop.
Save salihyalcin/74c860a39c5da9f054e01d858d17876b to your computer and use it in GitHub Desktop.
Kotlin json parsing.
inline fun <reified T> Context.jsonToClass(@RawRes resourceId: Int): T =
Gson().fromJson(resources.openRawResource(resourceId).bufferedReader().use { it.readText() }, T::class.java)
inline fun <reified T> Context.fromRemoteJsonToClass(json : String): T = Gson().fromJson(json, T::class.java)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment