commonMain.krono.serializers.LocalDateIsoSerializer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of krono-api-jvm Show documentation
Show all versions of krono-api-jvm Show documentation
An multiplatform interoperable datetime library
The newest version!
package krono.serializers
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import krono.LocalDate
@Serializer(forClass = LocalDate::class)
object LocalDateIsoSerializer : KSerializer {
override val descriptor = PrimitiveSerialDescriptor(
serialName = "krono.LocalDate",
kind = PrimitiveKind.STRING
)
override fun deserialize(decoder: Decoder): LocalDate = LocalDate(decoder.decodeString()).getOrThrow()
override fun serialize(encoder: Encoder, value: LocalDate) = encoder.encodeString(value.toIsoString())
}