whatisgithub

What is kotlinx.serialization?

kotlin/kotlinx.serialization — explained in plain English

Analysis updated 2026-06-26

5,912KotlinAudience · developerComplexity · 2/5LicenseSetup · moderate

In one sentence

JetBrains' official Kotlin library for converting data objects into JSON, Protobuf, CBOR, and other formats, and back again, across Android, desktop, web, and native targets from a single codebase.

Mindmap

mindmap
  root((repo))
    What it does
      Object to JSON
      JSON to object
      Multiple formats
    Formats
      JSON
      Protobuf
      CBOR
    Platforms
      Android
      JVM desktop
      Kotlin Multiplatform
    Setup
      Gradle plugin
      Annotations
      ProGuard rules
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Serialize and deserialize JSON API responses in an Android or Kotlin Multiplatform app

USE CASE 2

Convert Kotlin data classes to Protobuf for efficient binary data transfer between services

USE CASE 3

Share serialization logic across Android, desktop, and web targets in a Kotlin Multiplatform project

USE CASE 4

Replace Gson or Moshi with a Kotlin-native library that catches serialization errors at compile time

What is it built with?

KotlinGradleMavenProtobufJSON

How does it compare?

kotlin/kotlinx.serializationairbnb/mavericksz-huang/innertune
Stars5,9125,9335,936
LanguageKotlinKotlinKotlin
Setup difficultymoderateeasyeasy
Complexity2/53/52/5
Audiencedeveloperdevelopergeneral

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · moderate Time to first run · 30min

Requires adding both a Gradle compiler plugin and the runtime library dependency, two separate build.gradle entries.

Apache 2.0, use freely for any purpose, including commercial use, with attribution.

So what is it?

Kotlin/kotlinx.serialization is a library from JetBrains that handles converting Kotlin data objects into text formats and back again. When you have a piece of data in your app, like a user profile or a product record, this library can turn it into JSON text for sending to a server, and then convert incoming JSON text back into a usable object. It supports multiple formats beyond JSON, including Protobuf, CBOR, HOCON, and Properties files. The library works across different platforms: Android, desktop JVM apps, JavaScript runtimes, and native applications all use the same code and annotations. This is part of Kotlin's multiplatform approach, where a single codebase can target many environments without rewriting the serialization logic for each one. Setting it up involves two steps. First, you add a compiler plugin to your build configuration (Gradle or Maven), which reads your data classes at compile time and generates the code needed to serialize them. Second, you add the runtime library as a dependency. Then you mark any data class with @Serializable and call functions like Json.encodeToString() to produce JSON text, or Json.decodeFromString() to convert JSON back into your object. The README includes a short, working example showing both directions. For Android developers, the library includes ProGuard rules that keep serialization working after your app is minified for release. There is one caveat: if your data classes use named companion objects, a Kotlin language feature, you need to add a small set of extra ProGuard rules by hand. The README provides example rules for both standard ProGuard and R8, the newer code shrinker used in modern Android builds. The project is an official JetBrains library released under the Apache 2.0 license. New versions are published in tandem with each Kotlin compiler release, so it stays current with the language. Full documentation, a detailed serialization guide, and an API reference are available on the official Kotlin documentation site.

Copy-paste prompts

Prompt 1
Add kotlinx.serialization to my Android Gradle project and serialize a data class to a JSON string
Prompt 2
How do I deserialize a nested JSON API response into Kotlin data classes using kotlinx.serialization?
Prompt 3
Set up kotlinx.serialization in a Kotlin Multiplatform project targeting Android, JVM, and JS
Prompt 4
Migrate my Gson-based model serialization to kotlinx.serialization with @Serializable annotations
Prompt 5
How do I write the correct ProGuard rules for kotlinx.serialization in a release Android build that uses R8?

Frequently asked questions

What is kotlinx.serialization?

JetBrains' official Kotlin library for converting data objects into JSON, Protobuf, CBOR, and other formats, and back again, across Android, desktop, web, and native targets from a single codebase.

What language is kotlinx.serialization written in?

Mainly Kotlin. The stack also includes Kotlin, Gradle, Maven.

What license does kotlinx.serialization use?

Apache 2.0, use freely for any purpose, including commercial use, with attribution.

How hard is kotlinx.serialization to set up?

Setup difficulty is rated moderate, with roughly 30min to a first successful run.

Who is kotlinx.serialization for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.