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

com.caesarealabs.rpc4k.runtime.implementation.serializers.DateSerializers.kt Maven / Gradle / Ivy

There is a newer version: 0.7.1
Show newest version
@file:Suppress("FunctionName")

package com.caesarealabs.rpc4k.runtime.implementation.serializers

import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import java.time.Instant
import java.time.ZonedDateTime



/**
 * We serialize instant as an iso string
 */
object InstantIsoSerializer : KSerializer {
    override val descriptor: SerialDescriptor = String.serializer().descriptor

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

    override fun serialize(encoder: Encoder, value: Instant) = encoder.encodeString(value.toString())
}


/**
 * We serialize ZonedDateTime as an iso string
 */
object ZonedDateTimeIsoSerializer : KSerializer {
    override val descriptor: SerialDescriptor = String.serializer().descriptor

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

    override fun serialize(encoder: Encoder, value: ZonedDateTime) = encoder.encodeString(value.toString())
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy