Kotlin Serialization¶
Kotlin Serialization is the official multiplatform and multi-format serialization library for Kotlin.
If you need to (de)serialize Kotlin classes to/from JSON, you can enable Kotlin Serialization it in its simplest form:
settings:
kotlin:
serialization: json # JSON or other format
@Serializable classes, and adds dependencies on the serialization
runtime and JSON format libraries.
You can also customize the version of the Kotlin Serialization libraries using the full form of the configuration:
settings:
kotlin:
serialization:
format: json
version: 1.7.3
More control over serialization formats¶
If you don't need serialization format dependencies or if you need more control over them, you can use the following:
settings:
kotlin:
serialization: enabled # configures the compiler and serialization runtime library
dependencies section. This is useful in multiple cases:
-
if you need a format dependency only in tests:
settings: kotlin: serialization: enabled test-dependencies: - $kotlin.serialization.json -
if you need to customize the scope of the format dependencies:
settings: kotlin: serialization: enabled dependencies: - $kotlin.serialization.json: compile-only -
if you need to expose format dependencies transitively:
settings: kotlin: serialization: enabled dependencies: - $kotlin.serialization.json: exported -
if you need multiple formats:
settings: kotlin: serialization: enabled dependencies: - $kotlin.serialization.json - $kotlin.serialization.protobuf