Kotlin/kotlinx.serialization is a Kotlin project with 6.0k stars in the Mobile space. Kotlin multiplatform / multi-format serialization
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
Kotlin serialization consists of a compiler plugin, that generates visitor code for serializable classes,
runtime library with core serialization API and support libraries with various serialization formats.
Supports Kotlin classes marked as @Serializable and standard collections.
Provides JSON, Protobuf, CBOR, Hocon and Properties formats.
Complete multiplatform support: JVM, JS and Native.
Table of contents
Introduction and references
Setup
Gradle
1) Setting up the serialization plugin
2) Dependency on the JSON library
Android
Multiplatform (Common, JS, Native)
Maven
Bazel
Additional links
Kotlin serialization documentation
Full API reference
Submitting issues and PRs
Building this library
Introduction and references
Here is a small example.
import kotlinx.serialization.*
import kotlinx.serialization.json.*
@Serializable
data class Project(val name: String, val language: String)
fun main() {
// Serializing objects
val data = Project("kotlinx.serialization", "Kotlin")
val string = Json.encodeToString(data)
println(string) // {"name":"kotlinx.serialization","language":"Kotlin"}
// Deserializing back into objects
val obj = Json.decodeFromString<Project>(string)
println(obj) // Project(name=kotlinx.serialization, language=Kotlin)
}
You can get the full code here.
For detailed guides and examples, see the Kotlin serialization documentation.
You can find auto-generated documentation website on kotlinlang.org.
Setup
New versions of the serialization plugin are released in tandem with each new Kotlin compiler version.
Make sure you have the corresponding Kotlin plugin installed in the IDE, no additional plugins for IDE are required.
Gradle
To set up kotlinx.serialization, you have to do two things:
Add the serialization plugin.
Add the serialization library dependency.
1) Setting up the serialization plugin
You can set up the serialization plugin with the Kotlin plugin using the
Gradle plugins DSL:
Kotlin DSL:
plugins {
kotlin("jvm") version "2.4.10" // or kotlin("multiplatform") or any other kotlin plugin
kotlin("plugin.serialization") version "2.4.10"
}
Groovy DSL:
plugins {
id 'org.jetbrains.kotlin.multiplatform' version '2.4.10'
id 'org.jetbrains.kotlin.plugin.serialization' version '2.4.10'
}
Kotlin versions before 1.4.0 are not supported by the stable release of Kotlin serialization.
Using apply plugin (the old way)
First, you have to add the serialization plugin to your classpath as the other compiler plugins:
Kotlin DSL:
buildscript {
repositories { mavenCentral() }
dependencies {
val kotlinVersion = "2.4.10"
classpath(kotlin("gradle-plugin", version = kotlinVersion))
classpath(kotlin("serialization", version = kotlinVersion))
}
}
apply plugin: 'kotlin' // or 'kotlin-multiplatform' for multiplatform projects
apply plugin: 'kotlinx-serialization'
2) Dependency on the JSON library
After setting up the plugin, you have to add a dependency on the serialization library.
Note that while the plugin has version the same as the compiler one, runtime library has different coordinates, repository and versioning.
We also provide kotlinx-serialization-core artifact that contains all serialization API but does not have a bundled serialization format with it
Android
By default, proguard rules are supplied with the library.
These rules keep serializers for all serializable classes that are retained after shrinking,
so you don't need additional setup.
However, these rules do not affect serializable classes if they have named companion objects.
If you want to serialize classes with named companion objects, you need to add and edit rules below to your proguard-rules.pro configuration.
Note that the rules for R8 differ depending on the compatibility mode used.
Example of named companion rules for ProGuard and R8 compatibility mode
# Serializer for classes with named companion objects are retrieved using `getDeclaredClasses`.
# If you have any, replace classes with those containing named companion objects.
-keepattributes InnerClasses # Needed for `getDeclaredClasses`.
-if @kotlinx.serialization.Serializable class
com.example.myapplication.HasNamedCompanion, # <-- List serializable classes with named companions.
com.example.myapplication.HasNamedCompanion2
{
static **$* *;
}
-keepnames class <1>$$serializer { # -keepnames suffices; class is kept when serializer() is kept.
static <1>$$serializer INSTANCE;
}
Example of named companion rules for R8 full mode
# Serializer for classes with named companion objects are retrieved using `getDeclaredClasses`.
# If you have any, replace classes with those containing named companion objects.
-keepattributes InnerClasses # Needed for `getDeclaredClasses`.
-if @kotlinx.serialization.Serializable class
com.example.myapplication.HasNamedCompanion, # <-- List serializable classes with named companions.
com.example.myapplication.HasNamedCompanion2
{
static **$* *;
}
-keepnames class <1>$$serializer { # -keepnames suffices; class is kept when serializer() is kept.
static <1>$$serializer INSTANCE;
}
# Keep both serializer and serializable classes to save the attribute InnerClasses
-keepclasseswithmembers, allowshrinking, allowobfuscation, allowaccessmodification class
com.example.myapplication.HasNamedCompanion, # <-- List serializable classes with named companions.
com.example.myapplication.HasNamedCompanion2
{
*;
}
In case you want to exclude serializable classes that are used, but never serialized at runtime,
you will need to write custom rules with narrower class specifications.
Multiplatform (Common, JS, Native)
Most of the modules are also available for Kotlin/JS and Kotlin/Native.
You can add dependency to the required module right to the common source set:
commonMain {
dependencies {
// Works as common dependency as well as the platform one
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:$serialization_version"
}
}
The same artifact coordinates can be used to depend on platform-specific artifact in platform-specific source-set.
Maven
Ensure the proper version of Kotlin and serialization version:
How active is development on Kotlin/kotlinx.serialization?
The most recent commit recorded on Kotlin/kotlinx.serialization was 4 days ago, based on the GitHub push timestamp. The repository has 691 forks — one of the better signals of community interest.
How many stars does Kotlin/kotlinx.serialization have?
Kotlin/kotlinx.serialization has 6.0k GitHub stars — refresh the page for the live number, or check github.com/Kotlin/kotlinx.serialization. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
What else is in the Mobile space?
Kotlin/kotlinx.serialization is tracked by TopGit under the Mobile category, alongside 5 GitHub-tagged topics. Trending and Topics pages list peer repositories of comparable stars and language.
What language is Kotlin/kotlinx.serialization written in?
Kotlin/kotlinx.serialization is written primarily in Kotlin. GitHub's language field is based on the largest share of bytes in the default branch.
What topics is Kotlin/kotlinx.serialization associated with?
GitHub's repository topics for Kotlin/kotlinx.serialization: "cbor", "json", "kotlin", "protobuf", "serialization". TopGit's editorial category is Mobile.
Where do I read more about Kotlin/kotlinx.serialization?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/Kotlin/kotlinx.serialization is the definitive source.
Why is Kotlin/kotlinx.serialization categorized under Mobile?
TopGit places Kotlin/kotlinx.serialization in the Mobile category based on its GitHub topics and description (tagged: "cbor", "json", "kotlin"). Categories are assigned from real repository metadata, not editorial guesswork.
Read full README in the tab above.
Is kotlinx.serialization worth your time?
ChatGPT, Claude and Perplexity can all read this page. Ask one of them what it makes of kotlinx.serialization.