kotlinx.serialization is an official Kotlin library that provides a multiplatform serialization framework for converting Kotlin objects to and from multiple data formats. It uses a Kotlin compiler plugin to generate serializer and deserializer code at compile time, avoiding runtime reflection and preserving type safety through annotations like @Serializable. The library supports JVM, JS, and Native targets with platform-specific runtime libraries, enabling consistent serialization across all Kotlin environments.
The library distinguishes itself through its multi-format encoder-decoder abstraction, allowing the same serializable class to work with JSON, CBOR, ProtoBuf, and other formats without code changes. It supports polymorphic serialization for sealed classes and interfaces via a registry of subclass serializers, and allows custom serializer registration for types not covered by automatic generation. Additional capabilities include transient property exclusion to reduce payload size, and built-in JSON serialization for converting objects to and from JSON strings.
The project integrates with Gradle, Maven, and Bazel build systems for configuring the compiler plugin, and provides ProGuard and R8 rules to retain serializers during Android code shrinking.