Hi. Is there any examples of serialization? For ex...
# kotlinx-datetime
d
Hi. Is there any examples of serialization? For example with @Serializable Thanks
m
Do you mean making
kotlinx.datetime
types serializable?
Copy code
@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
It is planned kotlinx-datetime get Serialization support ootb, maybe an ETA should be great
j
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 🙂