were introduced in Kotlin 2.1.20
Then, kotlinx.serialization added support for these 2 types in v1.9.0, but that requires Kotlin 2.2
What are my options if I want to stay on Kotlin 2.1.20 and want to serialize kotlin.time.Instant types? Is the
compat
artifact useful for this situation?
j
jw
07/18/2025, 1:28 PM
It's single-digit LOC to write a custom serializer for instant.
jw
07/18/2025, 1:30 PM
You're basically just calling
toEpochMilliseconds
to
fromEpochMilliseconds
and you're done.
c
curioustechizen
07/18/2025, 1:32 PM
IIRC kotlinx.datetime had 2 separate serializers (one would use the ISO format and the other I think would save epoch seconds and nanoseconds components).
I need to be able to deserialize data that has already been stored (using the now-removed serializers from kotlinx.datetime). I can probably look into my persisted data to figure out which one of those is being used and then implement that in my app.
h
hfhbd
07/18/2025, 1:37 PM
The generated serializer uses the iso format. So to keep the same behavior with 2.2.0 you only need the iso serializer, that is incredible easy.