Retrofit 2 Kotlin Serialization Converter

A Converter.Factory for Kotlin's serialization support.

License

License

Categories

Categories

Kotlin Languages Retrofit Net HTTP Clients Serialization Data Data Formats
GroupId

GroupId

com.jakewharton.retrofit
ArtifactId

ArtifactId

retrofit2-kotlinx-serialization-converter
Last Version

Last Version

0.8.0
Release Date

Release Date

Type

Type

jar
Description

Description

Retrofit 2 Kotlin Serialization Converter
A Converter.Factory for Kotlin's serialization support.
Project URL

Project URL

https://github.com/JakeWharton/retrofit2-kotlinx-serialization-converter/
Source Code Management

Source Code Management

https://github.com/JakeWharton/retrofit2-kotlinx-serialization-converter/

Download retrofit2-kotlinx-serialization-converter

How to add to project

<!-- https://jarcasting.com/artifacts/com.jakewharton.retrofit/retrofit2-kotlinx-serialization-converter/ -->
<dependency>
    <groupId>com.jakewharton.retrofit</groupId>
    <artifactId>retrofit2-kotlinx-serialization-converter</artifactId>
    <version>0.8.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.jakewharton.retrofit/retrofit2-kotlinx-serialization-converter/
implementation 'com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:0.8.0'
// https://jarcasting.com/artifacts/com.jakewharton.retrofit/retrofit2-kotlinx-serialization-converter/
implementation ("com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:0.8.0")
'com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:jar:0.8.0'
<dependency org="com.jakewharton.retrofit" name="retrofit2-kotlinx-serialization-converter" rev="0.8.0">
  <artifact name="retrofit2-kotlinx-serialization-converter" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.jakewharton.retrofit', module='retrofit2-kotlinx-serialization-converter', version='0.8.0')
)
libraryDependencies += "com.jakewharton.retrofit" % "retrofit2-kotlinx-serialization-converter" % "0.8.0"
[com.jakewharton.retrofit/retrofit2-kotlinx-serialization-converter "0.8.0"]

Dependencies

compile (3)

Group / Artifact Type Version
com.squareup.retrofit2 : retrofit jar 2.6.4
org.jetbrains.kotlinx : kotlinx-serialization-core-jvm jar 1.0.0
org.jetbrains.kotlin : kotlin-stdlib jar 1.4.10

test (5)

Group / Artifact Type Version
junit : junit jar 4.13
com.squareup.okhttp3 : mockwebserver jar 3.14.7
com.google.truth : truth jar 1.0.1
org.jetbrains.kotlinx : kotlinx-serialization-protobuf jar 1.0.0
org.jetbrains.kotlinx : kotlinx-serialization-json jar 1.0.0

Project Modules

There are no modules declared in this project.

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 = "application/json".toMediaType()
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 Gradle:

implementation("com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:0.8.0")

or Maven:

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

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.

Versions

Version
0.8.0
0.7.0
0.6.0
0.5.0
0.4.0
0.3.0
0.2.0
0.1.0
0.0.1