Skip to content

Instantly share code, notes, and snippets.

@jmfayard
Created September 6, 2019 06:39
Show Gist options
  • Save jmfayard/e7b3c383db5e04344552754ad7eac354 to your computer and use it in GitHub Desktop.
Save jmfayard/e7b3c383db5e04344552754ad7eac354 to your computer and use it in GitHub Desktop.
object MoshiAdapters {
val moshi : Moshi = Moshi.Builder().build()
inline fun <reified T: Any> moshiAdapter(clazz: Class<T> = T::class.java): Lazy<JsonAdapter<T>>
= lazy { moshi.adapter(clazz) }
val movie: JsonAdapter<Movie> by moshiAdapter()
val user: JsonAdapter<User> by moshiAdapter()
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment