Skip to content

Files

Latest commit

Mar 3, 2025
085626a · Mar 3, 2025

History

History

methanol-moshi

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Dec 26, 2024
Mar 3, 2025
Dec 26, 2024

methanol-moshi

Adapters for JSON using moshi.

Installation

Gradle

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

Maven

<dependency>
  <groupId>com.github.mizosoft.methanol</groupId>
   <artifactId>methanol-moshi</artifactId>
   <version>1.8.2</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