commonMain.serialization.LocalTimeSerializer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fluid-time-macosx64 Show documentation
Show all versions of fluid-time-macosx64 Show documentation
Kotlin multiplatform date & time library
package io.fluidsonic.time
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*
@OptIn(ExperimentalSerializationApi::class)
@Serializer(forClass = LocalTime::class)
public object LocalTimeSerializer : KSerializer {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("kotlinx.datetime.LocalTime", PrimitiveKind.STRING)
override fun serialize(encoder: Encoder, value: LocalTime) {
encoder.encodeString(value.toString())
}
override fun deserialize(decoder: Decoder): LocalTime =
LocalTime.parse(decoder.decodeString())
}