From bc78bca553f9ab5cbf1b5e31a29239a23465f054 Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Tue, 3 Oct 2023 18:09:01 +0200 Subject: [PATCH 1/4] Migrate from kotlinx.serialization internal API to public one where applicable --- .../serializers/DateTimeUnitSerializers.kt | 29 ++++++++++--------- .../src/serializers/DayOfWeekSerializers.kt | 19 ++++-------- .../src/serializers/InstantSerializers.kt | 14 +++++---- .../src/serializers/LocalDateSerializers.kt | 11 ++++--- .../serializers/LocalDateTimeSerializers.kt | 13 ++++----- .../src/serializers/LocalTimeSerializers.kt | 5 ++-- .../src/serializers/MonthSerializers.kt | 18 +++++------- 7 files changed, 50 insertions(+), 59 deletions(-) diff --git a/core/common/src/serializers/DateTimeUnitSerializers.kt b/core/common/src/serializers/DateTimeUnitSerializers.kt index f003d9bfc..307fbb306 100644 --- a/core/common/src/serializers/DateTimeUnitSerializers.kt +++ b/core/common/src/serializers/DateTimeUnitSerializers.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 JetBrains s.r.o. + * Copyright 2019-2023 JetBrains s.r.o. * Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. */ @@ -35,7 +35,6 @@ public object TimeBasedDateTimeUnitSerializer: KSerializer break@loop // https://youtrack.jetbrains.com/issue/KT-42262 - else -> throw UnknownFieldException(elementIndex) + else -> throwUnknownIndexException(elementIndex) } } } } - if (!seen) throw MissingFieldException("nanoseconds") + if (!seen) throw MissingFieldException(missingField = "nanoseconds", serialName = descriptor.serialName) return DateTimeUnit.TimeBased(nanoseconds) } } @@ -82,7 +81,6 @@ public object DayBasedDateTimeUnitSerializer: KSerializer } @OptIn(ExperimentalSerializationApi::class) - @Suppress("INVISIBLE_MEMBER") // to be able to throw `MissingFieldException` override fun deserialize(decoder: Decoder): DateTimeUnit.DayBased { var seen = false var days = 0 @@ -98,12 +96,12 @@ public object DayBasedDateTimeUnitSerializer: KSerializer seen = true } CompositeDecoder.DECODE_DONE -> break@loop // https://youtrack.jetbrains.com/issue/KT-42262 - else -> throw UnknownFieldException(elementIndex) + else -> throwUnknownIndexException(elementIndex) } } } } - if (!seen) throw MissingFieldException("days") + if (!seen) throw MissingFieldException(missingField = "days", serialName = TimeBasedDateTimeUnitSerializer.descriptor.serialName) return DateTimeUnit.DayBased(days) } } @@ -129,7 +127,6 @@ public object MonthBasedDateTimeUnitSerializer: KSerializer break@loop // https://youtrack.jetbrains.com/issue/KT-42262 - else -> throw UnknownFieldException(elementIndex) + else -> throwUnknownIndexException(elementIndex) } } } } - if (!seen) throw MissingFieldException("months") + if (!seen) throw MissingFieldException(missingField = "months", serialName = descriptor.serialName) return DateTimeUnit.MonthBased(months) } } @@ -160,7 +157,7 @@ public object MonthBasedDateTimeUnitSerializer: KSerializer() { @@ -197,9 +194,9 @@ public object DateBasedDateTimeUnitSerializer: AbstractPolymorphicSerializer() { +public object DateTimeUnitSerializer : AbstractPolymorphicSerializer() { // https://youtrack.jetbrains.com/issue/KT-63939 private val impl by lazy(LazyThreadSafetyMode.PUBLICATION) { @@ -224,4 +221,8 @@ public object DateTimeUnitSerializer: AbstractPolymorphicSerializer { - private val impl = EnumSerializer("Month", DayOfWeek.values()) - - override val descriptor: SerialDescriptor - get() = impl.descriptor - - override fun deserialize(decoder: Decoder): DayOfWeek = impl.deserialize(decoder) - - override fun serialize(encoder: Encoder, value: DayOfWeek): Unit = impl.serialize(encoder, value) -} +public object DayOfWeekSerializer : KSerializer by createEnumSerializer( + "kotlinx.datetime.serializers.DayOfWeek", + DayOfWeek.values() +) diff --git a/core/common/src/serializers/InstantSerializers.kt b/core/common/src/serializers/InstantSerializers.kt index d2cb3df49..3cdb1683d 100644 --- a/core/common/src/serializers/InstantSerializers.kt +++ b/core/common/src/serializers/InstantSerializers.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 JetBrains s.r.o. + * Copyright 2019-2023 JetBrains s.r.o. * Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. */ @@ -18,7 +18,7 @@ import kotlinx.serialization.encoding.* * @see Instant.toString * @see Instant.parse */ -public object InstantIso8601Serializer: KSerializer { +public object InstantIso8601Serializer : KSerializer { override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("Instant", PrimitiveKind.STRING) @@ -37,7 +37,7 @@ public object InstantIso8601Serializer: KSerializer { * * JSON example: `{"epochSeconds":1607505416,"nanosecondsOfSecond":124000}` */ -public object InstantComponentSerializer: KSerializer { +public object InstantComponentSerializer : KSerializer { override val descriptor: SerialDescriptor = buildClassSerialDescriptor("Instant") { @@ -46,12 +46,11 @@ public object InstantComponentSerializer: KSerializer { } @OptIn(ExperimentalSerializationApi::class) - @Suppress("INVISIBLE_MEMBER") // to be able to throw `MissingFieldException` override fun deserialize(decoder: Decoder): Instant = decoder.decodeStructure(descriptor) { var epochSeconds: Long? = null var nanosecondsOfSecond = 0 - loop@while (true) { + loop@ while (true) { when (val index = decodeElementIndex(descriptor)) { 0 -> epochSeconds = decodeLongElement(descriptor, 0) 1 -> nanosecondsOfSecond = decodeIntElement(descriptor, 1) @@ -59,7 +58,10 @@ public object InstantComponentSerializer: KSerializer { else -> throw SerializationException("Unexpected index: $index") } } - if (epochSeconds == null) throw MissingFieldException("epochSeconds") + if (epochSeconds == null) throw MissingFieldException( + missingField = "epochSeconds", + serialName = descriptor.serialName + ) Instant.fromEpochSeconds(epochSeconds, nanosecondsOfSecond) } diff --git a/core/common/src/serializers/LocalDateSerializers.kt b/core/common/src/serializers/LocalDateSerializers.kt index 5f2770507..036e8ed8c 100644 --- a/core/common/src/serializers/LocalDateSerializers.kt +++ b/core/common/src/serializers/LocalDateSerializers.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 JetBrains s.r.o. + * Copyright 2019-2023 JetBrains s.r.o. * Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. */ @@ -47,7 +47,6 @@ public object LocalDateComponentSerializer: KSerializer { } @OptIn(ExperimentalSerializationApi::class) - @Suppress("INVISIBLE_MEMBER") // to be able to throw `MissingFieldException` override fun deserialize(decoder: Decoder): LocalDate = decoder.decodeStructure(descriptor) { var year: Int? = null @@ -59,12 +58,12 @@ public object LocalDateComponentSerializer: KSerializer { 1 -> month = decodeShortElement(descriptor, 1) 2 -> day = decodeShortElement(descriptor, 2) CompositeDecoder.DECODE_DONE -> break@loop // https://youtrack.jetbrains.com/issue/KT-42262 - else -> throw SerializationException("Unexpected index: $index") + else -> throwUnknownIndexException(index) } } - if (year == null) throw MissingFieldException("year") - if (month == null) throw MissingFieldException("month") - if (day == null) throw MissingFieldException("day") + if (year == null) throw MissingFieldException(missingField = "year", serialName = descriptor.serialName) + if (month == null) throw MissingFieldException(missingField = "month", serialName = descriptor.serialName) + if (day == null) throw MissingFieldException(missingField = "day", serialName = descriptor.serialName) LocalDate(year, month.toInt(), day.toInt()) } diff --git a/core/common/src/serializers/LocalDateTimeSerializers.kt b/core/common/src/serializers/LocalDateTimeSerializers.kt index 87d610630..2c9eae44f 100644 --- a/core/common/src/serializers/LocalDateTimeSerializers.kt +++ b/core/common/src/serializers/LocalDateTimeSerializers.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 JetBrains s.r.o. + * Copyright 2019-2023 JetBrains s.r.o. * Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. */ @@ -51,7 +51,6 @@ public object LocalDateTimeComponentSerializer: KSerializer { } @OptIn(ExperimentalSerializationApi::class) - @Suppress("INVISIBLE_MEMBER") // to be able to throw `MissingFieldException` override fun deserialize(decoder: Decoder): LocalDateTime = decoder.decodeStructure(descriptor) { var year: Int? = null @@ -74,11 +73,11 @@ public object LocalDateTimeComponentSerializer: KSerializer { else -> throw SerializationException("Unexpected index: $index") } } - if (year == null) throw MissingFieldException("year") - if (month == null) throw MissingFieldException("month") - if (day == null) throw MissingFieldException("day") - if (hour == null) throw MissingFieldException("hour") - if (minute == null) throw MissingFieldException("minute") + if (year == null) throw MissingFieldException(missingField = "year", serialName = descriptor.serialName) + if (month == null) throw MissingFieldException(missingField = "month", serialName = descriptor.serialName) + if (day == null) throw MissingFieldException(missingField = "day", serialName = descriptor.serialName) + if (hour == null) throw MissingFieldException(missingField = "hour", serialName = descriptor.serialName) + if (minute == null) throw MissingFieldException(missingField = "minute", serialName = descriptor.serialName) LocalDateTime(year, month.toInt(), day.toInt(), hour.toInt(), minute.toInt(), second.toInt(), nanosecond) } diff --git a/core/common/src/serializers/LocalTimeSerializers.kt b/core/common/src/serializers/LocalTimeSerializers.kt index 68362c29d..84a565bee 100644 --- a/core/common/src/serializers/LocalTimeSerializers.kt +++ b/core/common/src/serializers/LocalTimeSerializers.kt @@ -47,7 +47,6 @@ public object LocalTimeComponentSerializer : KSerializer { } @OptIn(ExperimentalSerializationApi::class) - @Suppress("INVISIBLE_MEMBER") // to be able to throw `MissingFieldException` override fun deserialize(decoder: Decoder): LocalTime = decoder.decodeStructure(descriptor) { var hour: Short? = null @@ -64,8 +63,8 @@ public object LocalTimeComponentSerializer : KSerializer { else -> throw SerializationException("Unexpected index: $index") } } - if (hour == null) throw MissingFieldException("hour") - if (minute == null) throw MissingFieldException("minute") + if (hour == null) throw MissingFieldException(missingField = "hour", serialName = descriptor.serialName) + if (minute == null) throw MissingFieldException(missingField = "minute", serialName = descriptor.serialName) LocalTime(hour.toInt(), minute.toInt(), second.toInt(), nanosecond) } diff --git a/core/common/src/serializers/MonthSerializers.kt b/core/common/src/serializers/MonthSerializers.kt index aea235cb1..0fc0c7040 100644 --- a/core/common/src/serializers/MonthSerializers.kt +++ b/core/common/src/serializers/MonthSerializers.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 JetBrains s.r.o. + * Copyright 2019-2023 JetBrains s.r.o. * Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file. */ @@ -16,14 +16,12 @@ import kotlinx.serialization.internal.* * * JSON example: `"JANUARY"` */ -@Suppress("INVISIBLE_MEMBER") -public object MonthSerializer: KSerializer { - private val impl = EnumSerializer("Month", Month.values()) +public object MonthSerializer : KSerializer by createEnumSerializer( + "kotlinx.datetime.serializers.Month", + Month.values()) - override val descriptor: SerialDescriptor - get() = impl.descriptor - - override fun deserialize(decoder: Decoder): Month = impl.deserialize(decoder) - - override fun serialize(encoder: Encoder, value: Month): Unit = impl.serialize(encoder, value) +// Until https://github.com/Kotlin/kotlinx.serialization/issues/2459 is resolved +internal fun > createEnumSerializer(serialName: String, values: Array): KSerializer { + @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") + return kotlinx.serialization.internal.EnumSerializer(serialName, values) } From 52430706c2d2265c76f329d51b926fbe14c8e04a Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Tue, 27 Feb 2024 11:46:50 +0100 Subject: [PATCH 2/4] ~fixup --- core/common/src/serializers/DateTimeUnitSerializers.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/common/src/serializers/DateTimeUnitSerializers.kt b/core/common/src/serializers/DateTimeUnitSerializers.kt index 307fbb306..6d3d1e1d3 100644 --- a/core/common/src/serializers/DateTimeUnitSerializers.kt +++ b/core/common/src/serializers/DateTimeUnitSerializers.kt @@ -101,7 +101,7 @@ public object DayBasedDateTimeUnitSerializer: KSerializer } } } - if (!seen) throw MissingFieldException(missingField = "days", serialName = TimeBasedDateTimeUnitSerializer.descriptor.serialName) + if (!seen) throw MissingFieldException(missingField = "days", serialName = descriptor.serialName) return DateTimeUnit.DayBased(days) } } From 25743304f699867bc8b063b951264890727e6ea7 Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Tue, 27 Feb 2024 18:19:26 +0100 Subject: [PATCH 3/4] ~change serial name to contain FQN all across the codebase --- .../src/serializers/DateTimePeriodSerializers.kt | 10 +++++----- core/common/src/serializers/DateTimeUnitSerializers.kt | 6 +++--- core/common/src/serializers/DayOfWeekSerializers.kt | 3 ++- core/common/src/serializers/InstantSerializers.kt | 4 ++-- core/common/src/serializers/LocalDateSerializers.kt | 4 ++-- .../common/src/serializers/LocalDateTimeSerializers.kt | 4 ++-- core/common/src/serializers/LocalTimeSerializers.kt | 4 ++-- core/common/src/serializers/MonthSerializers.kt | 3 ++- core/common/src/serializers/TimeZoneSerializers.kt | 6 +++--- 9 files changed, 23 insertions(+), 21 deletions(-) diff --git a/core/common/src/serializers/DateTimePeriodSerializers.kt b/core/common/src/serializers/DateTimePeriodSerializers.kt index eb5b0814a..3fd8e50fe 100644 --- a/core/common/src/serializers/DateTimePeriodSerializers.kt +++ b/core/common/src/serializers/DateTimePeriodSerializers.kt @@ -19,7 +19,7 @@ import kotlinx.serialization.encoding.* public object DateTimePeriodComponentSerializer: KSerializer { override val descriptor: SerialDescriptor = - buildClassSerialDescriptor("DateTimePeriod") { + buildClassSerialDescriptor("kotlinx.datetime.DateTimePeriod") { element("years", isOptional = true) element("months", isOptional = true) element("days", isOptional = true) @@ -81,7 +81,7 @@ public object DateTimePeriodComponentSerializer: KSerializer { public object DateTimePeriodIso8601Serializer: KSerializer { override val descriptor: SerialDescriptor = - PrimitiveSerialDescriptor("DateTimePeriod", PrimitiveKind.STRING) + PrimitiveSerialDescriptor("kotlinx.datetime.DateTimePeriod", PrimitiveKind.STRING) override fun deserialize(decoder: Decoder): DateTimePeriod = DateTimePeriod.parse(decoder.decodeString()) @@ -110,7 +110,7 @@ public object DatePeriodComponentSerializer: KSerializer { private fun unexpectedNonzero(fieldName: String, value: Int) = unexpectedNonzero(fieldName, value.toLong()) override val descriptor: SerialDescriptor = - buildClassSerialDescriptor("DatePeriod") { + buildClassSerialDescriptor("kotlinx.datetime.DatePeriod") { element("years", isOptional = true) element("months", isOptional = true) element("days", isOptional = true) @@ -166,7 +166,7 @@ public object DatePeriodComponentSerializer: KSerializer { public object DatePeriodIso8601Serializer: KSerializer { override val descriptor: SerialDescriptor = - PrimitiveSerialDescriptor("DatePeriod", PrimitiveKind.STRING) + PrimitiveSerialDescriptor("kotlinx.datetime.DatePeriod", PrimitiveKind.STRING) override fun deserialize(decoder: Decoder): DatePeriod = when (val period = DateTimePeriod.parse(decoder.decodeString())) { @@ -178,4 +178,4 @@ public object DatePeriodIso8601Serializer: KSerializer { encoder.encodeString(value.toString()) } -} \ No newline at end of file +} diff --git a/core/common/src/serializers/DateTimeUnitSerializers.kt b/core/common/src/serializers/DateTimeUnitSerializers.kt index 6d3d1e1d3..db2351e61 100644 --- a/core/common/src/serializers/DateTimeUnitSerializers.kt +++ b/core/common/src/serializers/DateTimeUnitSerializers.kt @@ -23,7 +23,7 @@ public object TimeBasedDateTimeUnitSerializer: KSerializer("nanoseconds") } } @@ -69,7 +69,7 @@ public object DayBasedDateTimeUnitSerializer: KSerializer // https://youtrack.jetbrains.com/issue/KT-63939 override val descriptor: SerialDescriptor by lazy(LazyThreadSafetyMode.PUBLICATION) { - buildClassSerialDescriptor("DayBased") { + buildClassSerialDescriptor("kotlinx.datetime.DayBased") { element("days") } } @@ -115,7 +115,7 @@ public object MonthBasedDateTimeUnitSerializer: KSerializer("months") } } diff --git a/core/common/src/serializers/DayOfWeekSerializers.kt b/core/common/src/serializers/DayOfWeekSerializers.kt index b1e80747a..d472b0da6 100644 --- a/core/common/src/serializers/DayOfWeekSerializers.kt +++ b/core/common/src/serializers/DayOfWeekSerializers.kt @@ -16,7 +16,8 @@ import kotlinx.serialization.internal.* * * JSON example: `"MONDAY"` */ +@Suppress("EnumValuesSoftDeprecate") // createEnumSerializer requires an array public object DayOfWeekSerializer : KSerializer by createEnumSerializer( - "kotlinx.datetime.serializers.DayOfWeek", + "kotlinx.datetime.DayOfWeek", DayOfWeek.values() ) diff --git a/core/common/src/serializers/InstantSerializers.kt b/core/common/src/serializers/InstantSerializers.kt index 3cdb1683d..6c0c07678 100644 --- a/core/common/src/serializers/InstantSerializers.kt +++ b/core/common/src/serializers/InstantSerializers.kt @@ -21,7 +21,7 @@ import kotlinx.serialization.encoding.* public object InstantIso8601Serializer : KSerializer { override val descriptor: SerialDescriptor = - PrimitiveSerialDescriptor("Instant", PrimitiveKind.STRING) + PrimitiveSerialDescriptor("kotlinx.datetime.Instant", PrimitiveKind.STRING) override fun deserialize(decoder: Decoder): Instant = Instant.parse(decoder.decodeString()) @@ -40,7 +40,7 @@ public object InstantIso8601Serializer : KSerializer { public object InstantComponentSerializer : KSerializer { override val descriptor: SerialDescriptor = - buildClassSerialDescriptor("Instant") { + buildClassSerialDescriptor("kotlinx.datetime.Instant") { element("epochSeconds") element("nanosecondsOfSecond", isOptional = true) } diff --git a/core/common/src/serializers/LocalDateSerializers.kt b/core/common/src/serializers/LocalDateSerializers.kt index 036e8ed8c..6d9f328ff 100644 --- a/core/common/src/serializers/LocalDateSerializers.kt +++ b/core/common/src/serializers/LocalDateSerializers.kt @@ -21,7 +21,7 @@ import kotlinx.serialization.encoding.* public object LocalDateIso8601Serializer: KSerializer { override val descriptor: SerialDescriptor = - PrimitiveSerialDescriptor("LocalDate", PrimitiveKind.STRING) + PrimitiveSerialDescriptor("kotlinx.datetime.LocalDate", PrimitiveKind.STRING) override fun deserialize(decoder: Decoder): LocalDate = LocalDate.parse(decoder.decodeString()) @@ -40,7 +40,7 @@ public object LocalDateIso8601Serializer: KSerializer { public object LocalDateComponentSerializer: KSerializer { override val descriptor: SerialDescriptor = - buildClassSerialDescriptor("LocalDate") { + buildClassSerialDescriptor("kotlinx.datetime.LocalDate") { element("year") element("month") element("day") diff --git a/core/common/src/serializers/LocalDateTimeSerializers.kt b/core/common/src/serializers/LocalDateTimeSerializers.kt index 2c9eae44f..d22d2243d 100644 --- a/core/common/src/serializers/LocalDateTimeSerializers.kt +++ b/core/common/src/serializers/LocalDateTimeSerializers.kt @@ -21,7 +21,7 @@ import kotlinx.serialization.encoding.* public object LocalDateTimeIso8601Serializer: KSerializer { override val descriptor: SerialDescriptor = - PrimitiveSerialDescriptor("LocalDateTime", PrimitiveKind.STRING) + PrimitiveSerialDescriptor("kotlinx.datetime.LocalDateTime", PrimitiveKind.STRING) override fun deserialize(decoder: Decoder): LocalDateTime = LocalDateTime.parse(decoder.decodeString()) @@ -40,7 +40,7 @@ public object LocalDateTimeIso8601Serializer: KSerializer { public object LocalDateTimeComponentSerializer: KSerializer { override val descriptor: SerialDescriptor = - buildClassSerialDescriptor("LocalDateTime") { + buildClassSerialDescriptor("kotlinx.datetime.LocalDateTime") { element("year") element("month") element("day") diff --git a/core/common/src/serializers/LocalTimeSerializers.kt b/core/common/src/serializers/LocalTimeSerializers.kt index 84a565bee..0becdc93a 100644 --- a/core/common/src/serializers/LocalTimeSerializers.kt +++ b/core/common/src/serializers/LocalTimeSerializers.kt @@ -21,7 +21,7 @@ import kotlinx.serialization.encoding.* public object LocalTimeIso8601Serializer : KSerializer { override val descriptor: SerialDescriptor = - PrimitiveSerialDescriptor("LocalTime", PrimitiveKind.STRING) + PrimitiveSerialDescriptor("kotlinx.datetime.LocalTime", PrimitiveKind.STRING) override fun deserialize(decoder: Decoder): LocalTime = LocalTime.parse(decoder.decodeString()) @@ -39,7 +39,7 @@ public object LocalTimeIso8601Serializer : KSerializer { public object LocalTimeComponentSerializer : KSerializer { override val descriptor: SerialDescriptor = - buildClassSerialDescriptor("LocalTime") { + buildClassSerialDescriptor("kotlinx.datetime.LocalTime") { element("hour") element("minute") element("second", isOptional = true) diff --git a/core/common/src/serializers/MonthSerializers.kt b/core/common/src/serializers/MonthSerializers.kt index 0fc0c7040..74d106549 100644 --- a/core/common/src/serializers/MonthSerializers.kt +++ b/core/common/src/serializers/MonthSerializers.kt @@ -16,8 +16,9 @@ import kotlinx.serialization.internal.* * * JSON example: `"JANUARY"` */ +@Suppress("EnumValuesSoftDeprecate") // createEnumSerializer requires an array public object MonthSerializer : KSerializer by createEnumSerializer( - "kotlinx.datetime.serializers.Month", + "kotlinx.datetime.Month", Month.values()) // Until https://github.com/Kotlin/kotlinx.serialization/issues/2459 is resolved diff --git a/core/common/src/serializers/TimeZoneSerializers.kt b/core/common/src/serializers/TimeZoneSerializers.kt index a4961ea34..ad41ba1b4 100644 --- a/core/common/src/serializers/TimeZoneSerializers.kt +++ b/core/common/src/serializers/TimeZoneSerializers.kt @@ -19,7 +19,7 @@ import kotlinx.serialization.encoding.* */ public object TimeZoneSerializer: KSerializer { - override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("TimeZone", PrimitiveKind.STRING) + override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("kotlinx.datetime.TimeZone", PrimitiveKind.STRING) override fun deserialize(decoder: Decoder): TimeZone = TimeZone.of(decoder.decodeString()) @@ -36,7 +36,7 @@ public object TimeZoneSerializer: KSerializer { */ public object FixedOffsetTimeZoneSerializer: KSerializer { - override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("FixedOffsetTimeZone", PrimitiveKind.STRING) + override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("kotlinx.datetime.FixedOffsetTimeZone", PrimitiveKind.STRING) override fun deserialize(decoder: Decoder): FixedOffsetTimeZone { val zone = TimeZone.of(decoder.decodeString()) @@ -63,7 +63,7 @@ public object FixedOffsetTimeZoneSerializer: KSerializer { */ public object UtcOffsetSerializer: KSerializer { - override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("UtcOffset", PrimitiveKind.STRING) + override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("kotlinx.datetime.UtcOffset", PrimitiveKind.STRING) override fun deserialize(decoder: Decoder): UtcOffset { return UtcOffset.parse(decoder.decodeString()) From fabc17b1feb90358b35c3a90de4c152aa3ab6905 Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Tue, 27 Feb 2024 18:38:36 +0100 Subject: [PATCH 4/4] ~highlight changes in serialized format --- .../common/test/DateTimeUnitSerializationTest.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/serialization/common/test/DateTimeUnitSerializationTest.kt b/serialization/common/test/DateTimeUnitSerializationTest.kt index b221fa5b7..e2b4f8b6e 100644 --- a/serialization/common/test/DateTimeUnitSerializationTest.kt +++ b/serialization/common/test/DateTimeUnitSerializationTest.kt @@ -48,14 +48,14 @@ class DateTimeUnitSerializationTest { repeat(100) { val days = Random.nextInt(1, Int.MAX_VALUE) val unit = DateTimeUnit.DayBased(days) - val json = "{\"type\":\"DayBased\",\"days\":$days}" + val json = "{\"type\":\"kotlinx.datetime.DayBased\",\"days\":$days}" assertEquals(json, Json.encodeToString(serializer, unit)) assertEquals(unit, Json.decodeFromString(serializer, json)) } repeat(100) { val months = Random.nextInt(1, Int.MAX_VALUE) val unit = DateTimeUnit.MonthBased(months) - val json = "{\"type\":\"MonthBased\",\"months\":$months}" + val json = "{\"type\":\"kotlinx.datetime.MonthBased\",\"months\":$months}" assertEquals(json, Json.encodeToString(serializer, unit)) assertEquals(unit, Json.decodeFromString(serializer, json)) } @@ -65,21 +65,21 @@ class DateTimeUnitSerializationTest { repeat(100) { val nanoseconds = Random.nextLong(1, Long.MAX_VALUE) val unit = DateTimeUnit.TimeBased(nanoseconds) - val json = "{\"type\":\"TimeBased\",\"nanoseconds\":${nanoseconds.toString()}}" // https://youtrack.jetbrains.com/issue/KT-39891 + val json = "{\"type\":\"kotlinx.datetime.TimeBased\",\"nanoseconds\":${nanoseconds.toString()}}" // https://youtrack.jetbrains.com/issue/KT-39891 assertEquals(json, Json.encodeToString(serializer, unit)) assertEquals(unit, Json.decodeFromString(serializer, json)) } repeat(100) { val days = Random.nextInt(1, Int.MAX_VALUE) val unit = DateTimeUnit.DayBased(days) - val json = "{\"type\":\"DayBased\",\"days\":$days}" + val json = "{\"type\":\"kotlinx.datetime.DayBased\",\"days\":$days}" assertEquals(json, Json.encodeToString(serializer, unit)) assertEquals(unit, Json.decodeFromString(serializer, json)) } repeat(100) { val months = Random.nextInt(1, Int.MAX_VALUE) val unit = DateTimeUnit.MonthBased(months) - val json = "{\"type\":\"MonthBased\",\"months\":$months}" + val json = "{\"type\":\"kotlinx.datetime.MonthBased\",\"months\":$months}" assertEquals(json, Json.encodeToString(serializer, unit)) assertEquals(unit, Json.decodeFromString(serializer, json)) } @@ -119,4 +119,4 @@ class DateTimeUnitSerializationTest { serialization(Json.serializersModule.serializer()) } -} \ No newline at end of file +}