Skip to content

Instantly share code, notes, and snippets.

@oscargrgm
Created July 16, 2021 08:06
Show Gist options
  • Save oscargrgm/3ab60ce0cd5d4f14ec60d761c0ab00bb to your computer and use it in GitHub Desktop.
Save oscargrgm/3ab60ce0cd5d4f14ec60d761c0ab00bb to your computer and use it in GitHub Desktop.
Deserialize any String into an object using Gson.
private inline fun <reified T> String.asModel(): T = Gson().fromJson(this, T::class.java)
// val result: String = ...
// val model = result.asModel<AnyModel>()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment