Deprecate TimeZone serialization#577
Conversation
| @@ -1,12 +1,11 @@ | |||
| /* | |||
| * Copyright 2019-2021 JetBrains s.r.o. | |||
| * Copyright 2025 JetBrains s.r.o. | |||
There was a problem hiding this comment.
IIRC, we can leave only the start date, not the end date
There was a problem hiding this comment.
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.", |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 (upd: I saw you addressed this)TimeZone.Companion.serializer() which would be gone)
980a540 to
e8c2620
Compare
* 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
e8c2620 to
1c74bb3
Compare
@kotlinx.serialization.Serializableannotation fromTimeZoneandFixedOffsetTimeZone.TimeZoneSerializerandFixedOffsetTimeZoneSerializerwith a warning..serializer()functions in their companion objects with a warning. Previously, this function used to be generated by thekotlinx.serializationcompiler plugin.Fixes #576