kotlinx.serialization
Official Kotlin serialization library by JetBrains. Uses a Kotlin compiler plugin to generate serializers at compile time for @Serializable classes. Supports JSON, Protobuf, CBOR, and custom formats. Works across Kotlin Multiplatform (JVM, JS, Native). No reflection required — serializers generated at compile time.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Compile-time code generation — no reflection, no runtime bytecode manipulation. No security concerns beyond input validation in custom serializers.
⚡ Reliability
Best When
Building Kotlin or Kotlin Multiplatform applications that need compile-time safe, reflection-free serialization.
Avoid When
You need XML support, Java interop with Jackson annotations, or are working in a pure Java codebase.
Use Cases
- • Serialize/deserialize Kotlin data classes to/from JSON in Ktor, Spring Kotlin, or KMM applications with @Serializable annotation
- • Build Kotlin Multiplatform (KMM) models with shared serialization logic across Android, iOS, and backend targets
- • Encode Kotlin objects to Protobuf or CBOR for compact binary serialization in performance-sensitive applications
- • Implement custom serializers for types that can't be annotated (third-party classes) using KSerializer<T>
- • Handle JSON polymorphism with sealed classes using @SerialName annotations for type discriminators
Not For
- • POJO serialization from Java code — kotlinx.serialization requires Kotlin with the compiler plugin; use Jackson or Gson for pure Java
- • XML serialization — kotlinx.serialization doesn't include an XML format; use kotlin-xml-builder or Jsoup for XML
- • Dynamic/untyped JSON manipulation — for ad-hoc JSON manipulation without type classes, use kotlinx.serialization's JsonElement API or consider a JSON library
Interface
Authentication
Library — no auth needed.
Pricing
JetBrains open source library.
Agent Metadata
Known Gotchas
- ⚠ Requires the Kotlin serialization Gradle plugin (kotlin('plugin.serialization')) — forgetting this causes confusing 'Serializer not found' errors at runtime
- ⚠ All serialized classes must be annotated with @Serializable — third-party classes require custom KSerializer implementations
- ⚠ Default JSON configuration is strict — unknown keys throw exceptions unless Json { ignoreUnknownKeys = true } is configured
- ⚠ Polymorphism requires explicit registration with SerializersModule — sealed classes work out of the box but open class hierarchies need manual configuration
- ⚠ Kotlin's default parameter values don't automatically become JSON defaults — use @Required or handle missing fields explicitly
- ⚠ v1.5+ changed the encodeDefaults behavior — previously fields with default values were omitted by default, now they're included; check Json configuration when migrating
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for kotlinx.serialization.
Scores are editorial opinions as of 2026-03-06.