commonMain.app.moviebase.trakt.core.LocalDateTimeSerializer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of trakt-api-jvm Show documentation
Show all versions of trakt-api-jvm Show documentation
Kotlin Multiplatform library to access the Trakt API.
package app.moviebase.trakt.core
import kotlinx.datetime.LocalDateTime
import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.nullable
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
class LocalDateTimeSerializer : KSerializer {
private val delegate = String.serializer().nullable
override val descriptor: SerialDescriptor get() = delegate.descriptor
override fun deserialize(decoder: Decoder): LocalDateTime? = delegate.deserialize(decoder)?.tryLocalDateTime()
override fun serialize(encoder: Encoder, value: LocalDateTime?) = delegate.serialize(encoder, value?.toString())
}