Skip to content
A Retrofit 2 Converter.Factory for Kotlin serialization.
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.buildscript Initial version. Jan 8, 2018
gradle Gradle 4.10.2 Sep 22, 2018
src Change factory to be an extension function Feb 24, 2019
.gitignore
.travis.yml
CHANGELOG.md Prepare version 0.3.0 Feb 25, 2019
LICENSE.txt
README.md Prepare version 0.3.0 Feb 25, 2019
build.gradle Update to Kotlin 1.3.20, Serialization 0.10.0, Retrofit 2.5.0 Jan 31, 2019
gradle.properties Prepare next development version Feb 25, 2019
gradlew
gradlew.bat Initial version. Jan 8, 2018

README.md

Kotlin Serialization Converter

A Retrofit 2 Converter.Factory for Kotlin serialization.

Usage

Add a converter factory when building your Retrofit instance using the asConverterFactory extension function:

val contentType = MediaType.get("application/json")
val retrofit = Retrofit.Builder()
    .baseUrl("https://example.com/")
    .addConverterFactory(Json.asConverterFactory(contentType))
    .build()

Response body types (e.g., Call<User>) and @Body types (e.g., @Body user: User) will now use the supplied serializer.

Because Kotlin serialization is so flexible in the types it supports, these converters assume that they can handle all types. If you are mixing this converter with another, you must add this instance last to allow the other converters a chance to see their types.

Download

Download the latest JAR or grab via Maven:

<dependency>
  <groupId>com.jakewharton.retrofit</groupId>
  <artifactId>retrofit2-kotlinx-serialization-converter</artifactId>
  <version>0.3.0</version>
</dependency>

or Gradle:

implementation 'com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:0.3.0'

Snapshots of the development version are available in Sonatype's snapshots repository.

License

Copyright 2018 Jake Wharton

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
You can’t perform that action at this time.