Kotlin Serialization is a cross-platform and multi-format framework for data serialization—converting trees of objects to strings, byte arrays, or other serial representations and back. Kotlin Serialization fully supports and enforces the Kotlin type system, making sure only valid objects can be deserialized.
Kotlin Serialization is not just a library. It is a compiler plugin that is bundled with the Kotlin compiler distribution itself. Build configuration is explained in README.md. Once the project is set up, we can start serializing some classes.
Chapter 1. Basic Serialization (start reading here)
- Basics
- Serializable classes
- Backing fields are serialized
- Constructor properties requirement
- Data validation
- Optional properties
- Optional property initializer call
- Required properties
- Transient properties
- Defaults are not encoded
- Nullable properties
- Type safety is enforced
- Referenced objects
- No compression of repeated references
- Generic classes
- Serial field names
Chapter 2. Builtin Classes
Chapter 3. Serializers
- Introduction to serializers
- Custom serializers
- Primitive serializer
- Composite serializer via surrogate
- Hand-written composite serializer
- Sequential decoding protocol (experimental)
- Serializing 3rd party classes
- Passing a serializer manually
- Specifying serializer on a property
- Specifying serializers for a file
- Custom serializers for a generic type
- Format-specific serializers
- Contextual serialization
- Deriving external serializer for another Kotlin class (experimental)
Chapter 4. Polymorphism
- Closed polymorphism
- Open polymorphism
- Registered subclasses
- Serializing interfaces
- Property of an interface type
- Static parent type lookup for polymorphism
- Explicitly marking polymorphic class properties
- Registering multiple superclasses
- Polymorphism and generic classes
- Merging library serializers modules
- Default polymorphic type handler for deserialization
Chapter 5. JSON Features