https://kotlinlang.org logo
Title
d

Darren Bell

11/19/2020, 4:10 PM
Hi. Is there any examples of serialization? For example with @Serializable Thanks
m

Marc Knaup

11/19/2020, 5:06 PM
Do you mean making
kotlinx.datetime
types serializable?
@Serializer(forClass = Instant::class)
internal object InstantSerializer : KSerializer<Instant> {

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


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


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

Javier

11/19/2020, 5:56 PM
It is planned kotlinx-datetime get Serialization support ootb, maybe an ETA should be great
j

Joost Klitsie

11/20/2020, 8:06 AM
I think serialization of times is a pain point in general, being able to just pass in datetimes or instant in your DTO and magically receive it on the other end would be great 🙂