Skip to content

Files

Latest commit

 

History

History
101 lines (83 loc) · 4.34 KB

File metadata and controls

101 lines (83 loc) · 4.34 KB

🔌 Support of kotlinx.serialization

Latest version Embedded Kotlin Kotlin language kotlinx.serialization

JVM Platform JS Platform iOS x64 Platform iOS Simulator arm64 Platform Linux x64 Platform macOS x64 Platform macOS arm64 Platform MinGW x64 Platform

This module provides support for serializing types from Kotools Types using the kotlinx.serialization library.

🛠️ Installation

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>

👨‍💻 Usage

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.