Kotlin implementation of UtaFormatix Data Format.
This library has full support of Kotlin multiplatform projects.
Kotlin DSL:
repositories {
mavenCentral()
}
dependencies {
implementation("com.sdercolin.utaformatix:utaformatix-data:1.0.0")
}
Groovy DSL:
repositories {
mavenCentral()
}
dependencies {
implementation "com.sdercolin.utaformatix:utaformatix-data:1.0.0"
}
The classes are marked @Serializable
so you can
use kotlinx.serialization to serialize/deserialize them.
In your build.gradle.kts
:
plugins {
kotlin("jvm") version "1.6.21"
kotlin("plugin.serialization") version "1.6.21"
}
// ...
dependencies {
// ...
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.3")
// ...
}
In your code:
import com.sdercolin.utaformatix.data.Document
val jsonSerializer = Json {
isLenient = true
ignoreUnknownKeys = true
encodeDefaults = true
explicitNulls = false
}
fun deserialize(json: String): Document {
return jsonSerializer.decodeFromString(Document.serializer(), json)
}
fun serialize(document: Document): String {
return jsonSerializer.encodeToString(Document.serializer(), document)
}