All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.serialization.LocalDateSerializer.kt Maven / Gradle / Ivy

There is a newer version: 0.18.0
Show newest version
package io.fluidsonic.time

import kotlinx.datetime.*
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.*


@OptIn(ExperimentalSerializationApi::class)
@Serializer(forClass = LocalDate::class)
public object LocalDateSerializer : KSerializer {

	override val descriptor: SerialDescriptor =
		PrimitiveSerialDescriptor("kotlinx.datetime.LocalDate", PrimitiveKind.STRING)


	override fun serialize(encoder: Encoder, value: LocalDate) {
		encoder.encodeString(value.toString())
	}


	override fun deserialize(decoder: Decoder): LocalDate =
		LocalDate.parse(decoder.decodeString())
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy