Skip to content

feat(core): support kotlin.time.Instant#478

Merged
Chuckame merged 11 commits into
avro-kotlin:mainfrom
kangwooc:main
Jul 19, 2026
Merged

feat(core): support kotlin.time.Instant#478
Chuckame merged 11 commits into
avro-kotlin:mainfrom
kangwooc:main

Conversation

@kangwooc

@kangwooc kangwooc commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add native serializer support for kotlin.time.Instant without adding a kotlinx-datetime dependency.
  • Encode as timestamp-millis by default, with writer-schema support for timestamp-micros, timestamp-nanos, and ISO-8601 strings.
  • Update the public API dump and reject out-of-range Avro timestamp conversions instead of overflowing or clamping.

Testing

  • ./gradlew :core:test --tests '*KotlinInstantEncodingTest' --tests '*KotlinInstantDecodingTest' :core:apiCheck
  • ./gradlew check

Closes #417

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
@Chuckame

Copy link
Copy Markdown
Member

I've been near to merge your PR, however I would have expect the std kotlin.time.Instant to be used, instead of the "additional" other Instant from the kotlinx datetime library, to not depend on another library (not all kotlin projects needs the kotlinX datetime library).

Please adapt it to this kotlin.time.Instant.

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!

@kangwooc

kangwooc commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

@Chuckame then do i create another pr and closed this?
if you are okay, i could keep working on this pr.

@Chuckame

Copy link
Copy Markdown
Member

As you prefer, you can reuse this PR also, as mostly only the package name will change in the changes.

@kangwooc kangwooc changed the title feat(core): support kotlinx.datetime.Instant feat(core): support kotlin.time.Instant Jun 19, 2026
Comment thread README.md Outdated
Comment thread README.md Outdated
@kangwooc
kangwooc requested a review from Chuckame June 22, 2026 07:21
Comment thread README.md
@kangwooc

kangwooc commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

@Chuckame just for reminder, would you review this?

@Chuckame Chuckame left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Near to final code, sorry for the delay again

@kangwooc
kangwooc requested a review from Chuckame July 17, 2026 03:43
@Chuckame
Chuckame merged commit ce09c27 into avro-kotlin:main Jul 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide kotlin.time.Instant serializer

2 participants