Kotlin’s a great language for JSON
Jesse Wilson

FYI, there is a pattern I really like when using moshi with Kotlin :

I was feeling a bit lazy having to create the moshi adapters each time I wanted to use fromString() / toString(). Instead I now do

val issue = Adapters.Issue.fromJson(issueJson)

What I did here is simply to create a singleton Adapters that contains one property JsonAdapter<T> for each type I’m interested in, initialized with that little handy reified function

/** Moshi Adapters **/
object Adapters {
val moshi = Moshi.Builder().build()
    val Issue: JsonAdapter<Issue> = adapter()
    val User: JsonAdapter<User> = adapter().indent("  ").nullSafe()
val ErrorResponse: JsonAdapter<ErrorResponse> = adapter()
    private inline fun <reified T> adapter(): JsonAdapter<T>
= moshi.adapter(T::class.java)

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.