Skip to content

methanol-moshi

Adapters for JSON using moshi.

Installation

Gradle

implementation("com.github.mizosoft.methanol:methanol-moshi:1.7.0")

Maven

<dependency>
  <groupId>com.github.mizosoft.methanol</groupId>
   <artifactId>methanol-moshi</artifactId>
   <version>1.7.0</version>
</dependency>

Usage

val moshi: Moshi = Moshi.Builder().build()
val client = Client {
  adapterCodec {
    +MoshiAdapter.Encoder(moshi, MediaType.APPLICATION_JSON)
    +MoshiAdapter.Decoder(moshi, MediaType.APPLICATION_JSON)
  }
}

data class Person(val name: String)

var bruceLee = Person("Bruce Lee")
val response: Response<Person> = client.post(".../echo") {
  body(bruceLee, MediaType.APPLICATION_JSON)
}
assertThat(response.body()).isEqualTo(bruceLee)

Legacy Adapters

See Legacy Adapters