add KotlinxJodaTimeConverter

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2024-03-07 10:12:24 +01:00
parent a576e5f41c
commit 3d7a72f189
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B

View file

@ -0,0 +1,22 @@
package com.nextcloud.talk.models.json.converters
import kotlinx.serialization.KSerializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import org.joda.time.DateTime
object KotlinxJodaTimeConverter : KSerializer<DateTime> {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("DateTime", PrimitiveKind.STRING)
override fun serialize(encoder: Encoder, value: DateTime) {
encoder.encodeString(value.toString())
}
override fun deserialize(decoder: Decoder): DateTime =
DateTime.parse(decoder.decodeString())
}