kotlinx.serialization Setup
Add the plugin.
What is kotlinx.serialization?
kotlinx.serialization is the official Kotlin library for converting objects to and from formats like JSON.
- Pure Kotlin, multiplatform-ready
- Compile-time code generation (no reflection)
- Maintained by JetBrains
It works with a compiler plugin plus a runtime library.
Why a Compiler Plugin?
Unlike reflection-based libraries, kotlinx.serialization generates serializers at compile time.
- Faster, no runtime reflection cost
- Works on Kotlin/Native and JS where reflection is limited
- Type-safe and verified by the compiler
This is why you must apply the kotlin-serialization plugin, not just add a dependency.
All lessons in this course
- kotlinx.serialization Setup
- Serializable Classes
- JSON Encoding and Decoding
- Custom Serializers