Skip to content

Deprecate TimeZone serialization#577

Merged
dkhalanskyjb merged 2 commits into
masterfrom
dkhalanskyjb/remove-timezone-serializers
Apr 15, 2026
Merged

Deprecate TimeZone serialization#577
dkhalanskyjb merged 2 commits into
masterfrom
dkhalanskyjb/remove-timezone-serializers

Conversation

@dkhalanskyjb
Copy link
Copy Markdown
Collaborator

  • Remove the @kotlinx.serialization.Serializable annotation from TimeZone and FixedOffsetTimeZone.
  • Deprecate TimeZoneSerializer and FixedOffsetTimeZoneSerializer with a warning.
  • Introduce and deprecate the .serializer() functions in their companion objects with a warning. Previously, this function used to be generated by the kotlinx.serialization compiler plugin.

Fixes #576

@@ -1,12 +1,11 @@
/*
* Copyright 2019-2021 JetBrains s.r.o.
* Copyright 2025 JetBrains s.r.o.
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.

IIRC, we can leave only the start date, not the end date

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We can remove the copyright notices completely: Kotlin/kotlinx.coroutines#4016

* JSON example: `"Europe/Berlin"`
*/
@Deprecated(
"Serializing TimeZone is discouraged. Please serialize the id String instead.",
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.

id String sounds weird. Maybe you want id: String? Or since this is more of a text message, string id sounds better IMO

* @sample kotlinx.datetime.test.samples.TimeZoneSamples.usage
*/
@Serializable(with = TimeZoneSerializer::class)
public expect open class TimeZone {
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.

Note that the moment you remove @Serializable(with=...) annotation from type, it is shown as red with SERIALIZER_NOT_FOUND where it was used in any @Serializable user class. Sadly, we do not have any kind of deprecation migration for that; so I suggest raising all @Deprecated here to ERROR just to speedup this process

Copy link
Copy Markdown
Collaborator Author

@dkhalanskyjb dkhalanskyjb Nov 3, 2025

Choose a reason for hiding this comment

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

The idea is to keep it WARNING for now so that people can work around the SERIALIZER_NOT_FOUND issue by adding their own annotation to the TimeZone field. Then, after a migratory period, when we expect such annotations to be removed as well, the deprecation can be promoted to ERROR.

Does this approach make sense?

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.

I think most of the people wouldn't be able to guess that red code with deprecation forces them to use @Serializable(TimeZoneSerializer::class) (also with deprecation). But let's try, there's hardly another approach if you do not want to skip WARNING stage.

Copy link
Copy Markdown
Member

@sandwwraith sandwwraith Apr 14, 2026

Choose a reason for hiding this comment

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

Although I would still advocate going directly to ERROR as kotlinx-datetime is still 0.x and we are breaking binary compatibility anyway (missing @serializable would lead to linkage errors, as we try to access TimeZone.Companion.serializer() which would be gone) (upd: I saw you addressed this)

Comment thread core/common/src/TimeZone.kt
dkhalanskyjb and others added 2 commits April 2, 2026 13:07
* Remove the `@kotlinx.serialization.Serializable`
  annotation from `TimeZone` and `FixedOffsetTimeZone`.
* Deprecate `TimeZoneSerializer`
  and `FixedOffsetTimeZoneSerializer`
  with a warning.
* Introduce and deprecate the `.serializer()`
  functions in their companion objects with a warning.
  Previously, this function used to be generated by the
  `kotlinx.serialization` compiler plugin.

Fixes #576
@dkhalanskyjb dkhalanskyjb force-pushed the dkhalanskyjb/remove-timezone-serializers branch from e8c2620 to 1c74bb3 Compare April 2, 2026 11:07
@dkhalanskyjb dkhalanskyjb requested a review from sandwwraith April 2, 2026 12:16
@dkhalanskyjb dkhalanskyjb merged commit b0b934b into master Apr 15, 2026
1 check passed
@dkhalanskyjb dkhalanskyjb deleted the dkhalanskyjb/remove-timezone-serializers branch April 15, 2026 07:52
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.

Remove TimeZone and FixedOffsetTimeZone serialization

3 participants