feat(core): support kotlin.time.Instant#478
Conversation
Add native support for kotlinx.datetime.Instant so users can encode and decode Kotlin Instant values without registering a contextual serializer manually. The serializer defaults to Avro timestamp-millis, supports writer-schema selection of timestamp-micros and timestamp-nanos, and still allows ISO-8601 strings through @AvroStringable. Nanos conversion uses checked arithmetic so out-of-range instants fail instead of silently wrapping into unrelated timestamps. Constraint: Issue avro-kotlin#417 requests Kotlin Instant support with timestamp millis, micros, and nanos support Constraint: binary-compatibility-validator requires the new public serializer in core/api/core.api Rejected: Keep the overflow fix as a separate review commit | the PR should present this feature as one coherent change Confidence: high Scope-risk: narrow Tested: ./gradlew :core:test --tests '*KotlinInstantEncodingTest' --tests '*KotlinInstantDecodingTest' :core:apiCheck Tested: ./gradlew check
|
I've been near to merge your PR, however I would have expect the std Please adapt it to this If we really want to add support for kotlinx datetime, let's try to propose a modular approach of serializing a timestamp millis/micros/nanos, which would be used by jvm's Instant/Date, the kotlin's Instant, or any other non-kotlin standard time modules. It could be then used on the user-application's side (preferred solution for uncommon time libraries), another avro4k module (preferred for common/official kotlin's libraries, like ktor does), or included in the core lib but optionally (less preferred). Let's put this modularity into another PR 🙏 Thanks again for your work! |
|
@Chuckame then do i create another pr and closed this? |
|
As you prefer, you can reuse this PR also, as mostly only the package name will change in the changes. |
|
@Chuckame just for reminder, would you review this? |
Chuckame
left a comment
There was a problem hiding this comment.
Near to final code, sorry for the delay again
Summary
kotlin.time.Instantwithout adding akotlinx-datetimedependency.timestamp-millisby default, with writer-schema support fortimestamp-micros,timestamp-nanos, and ISO-8601 strings.Testing
./gradlew :core:test --tests '*KotlinInstantEncodingTest' --tests '*KotlinInstantDecodingTest' :core:apiCheck./gradlew checkCloses #417