commonMain.app.moviebase.tmdb.core.LocalDateSerializer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tmdb-api Show documentation
Show all versions of tmdb-api Show documentation
A Kotlin Multiplatform library to access the TMDB API.
The newest version!
package app.moviebase.tmdb.core
import kotlinx.datetime.LocalDate
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
/**
* Custom serializer to handle empty text in TMDB.
*/
internal class LocalDateSerializer : KSerializer {
private val delegate = String.serializer().nullable
override val descriptor: SerialDescriptor get() = delegate.descriptor
override fun deserialize(decoder: Decoder): LocalDate? = delegate.deserialize(decoder)?.tryLocalDate()
override fun serialize(encoder: Encoder, value: LocalDate?) = delegate.serialize(encoder, value?.toString())
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy