🔌 Support of kotlinx.serialization
This module provides support for serializing types from Kotools Types using the kotlinx.serialization library.
You can add this module to your project by using Gradle or Maven.
Just replace the $version
or the ${kotools.types.version}
variables by the
latest version or by another one available
in the changelog.
Important
Note that this module doesn't exist for versions prior Kotools Types 4.5.1.
Gradle - Kotlin DSL
implementation("org.kotools:types-kotlinx-serialization:$version")
Gradle - Groovy DSL
implementation "org.kotools:types-kotlinx-serialization:$version"
Maven
<dependencies>
<dependency>
<groupId>org.kotools</groupId>
<artifactId>types-kotlinx-serialization</artifactId>
<version>${kotools.types.version}</version>
</dependency>
</dependencies>
For using this module, you need to import the serializers module needed when configuring the serialization format.
Here's an example using default serializers from Kotools Types with the JavaScript Object Notation (JSON) format:
val format = Json { serializersModule = KotoolsTypesSerializersModule() }
val address: EmailAddress = EmailAddress.orThrow("contact@kotools.org")
val encoded: String = format.encodeToString(address)
assertEquals(expected = "\"$address\"", encoded)
val decoded: EmailAddress = format.decodeFromString(encoded)
assertEquals(expected = address, decoded)
See the API reference of the KotoolsTypesSerializersModule()
function for
more details.