Open
Description
Many APIs return a unix timestamp, the seconds from the epoch as Long
.
Although the serializer is easy to create, it could be provided.
public object InstantUnixSecondsSerializer : KSerializer<Instant> {
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("Instant", PrimitiveKind.LONG)
override fun deserialize(decoder: Decoder): Instant = Instant.fromEpochSeconds(decoder.decodeLong())
override fun serialize(encoder: Encoder, value: Instant) {
encoder.encodeLong(value.epochSeconds)
}
}