Add kotlin.time.Instant serializers
Can be merged after moving to Kotlin 2.1.20, which introduces kotlin.time.Instant.
kotlinx.datetime.Instant entered the stdlib as kotlin.time.Instant, and so kotlinx.serialization takes over its serializers. See https://github.com/Kotlin/KEEP/pull/387
For InstantSerializer to be picked by the compiler automatically, it should be added to this list: https://github.com/JetBrains/kotlin/blob/ab7d84b1ff9fd99c4035fc1c65f9ae7d50a10aa4/plugins/kotlinx-serialization/kotlinx-serialization.common/src/org/jetbrains/kotlinx/serialization/compiler/resolve/NamingConventions.kt#L215
For now, you can use serializer(typeOf<Instant>()) to force runtime lookup instead of the intrinsic one. Do not forget to add smth like // serializer<Instant>() TODO: uncomment in 2.1.20
Something like this? https://github.com/JetBrains/kotlin/pull/5412
Note that even after merging Kotlin PR, changes in this one are required, because compiler is not updated instantly
Sure thing! Are there any other changes I should make in addition to that? For example, I copied the test from kotlinx-datetime directly, without trying to adjust its structure to that of surrounding tests, and I'm not sure that I've even put it in the right place.
Any chance to get a review (and a release) soon?
@valeriyo
and now what?
Use Instant.serializer() from the package kotlinx.serialization.builtins: https://github.com/Kotlin/kotlinx.serialization/blob/master/core/commonMain/src/kotlinx/serialization/builtins/BuiltinSerializers.kt#L272
@valeriyo,
kotlin.time.Instant isn't annotated.
It's not annotated for the same reason Long and Int isn't: the compiler automatically uses the required serializer if kotlinx.serialization 1.9.0 is present. The IDE may highlight the code as red, but it should still compile.
@valeriyo, please share a sample project where the issue happens. I couldn't make it reproduce during testing (https://github.com/Kotlin/kotlinx.serialization/issues/3026#issuecomment-3018700470).
@valeriyo, the project you linked compiles without errors and the reason why IDE highlights the code despite it being perfectly fine was described here: https://github.com/Kotlin/kotlinx.serialization/issues/3026#issuecomment-3018712811.