11/*
2- * Copyright 2019-2021 JetBrains s.r.o.
2+ * Copyright 2019-2023 JetBrains s.r.o.
33 * Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
44 */
55
@@ -23,7 +23,7 @@ public object TimeBasedDateTimeUnitSerializer: KSerializer<DateTimeUnit.TimeBase
2323
2424 // https://youtrack.jetbrains.com/issue/KT-63939
2525 override val descriptor: SerialDescriptor by lazy(LazyThreadSafetyMode .PUBLICATION ) {
26- buildClassSerialDescriptor(" TimeBased" ) {
26+ buildClassSerialDescriptor(" kotlinx.datetime. TimeBased" ) {
2727 element<Long >(" nanoseconds" )
2828 }
2929 }
@@ -35,7 +35,6 @@ public object TimeBasedDateTimeUnitSerializer: KSerializer<DateTimeUnit.TimeBase
3535 }
3636
3737 @OptIn(ExperimentalSerializationApi ::class )
38- @Suppress(" INVISIBLE_MEMBER" ) // to be able to throw `MissingFieldException`
3938 override fun deserialize (decoder : Decoder ): DateTimeUnit .TimeBased {
4039 var seen = false
4140 var nanoseconds = 0L
@@ -51,12 +50,12 @@ public object TimeBasedDateTimeUnitSerializer: KSerializer<DateTimeUnit.TimeBase
5150 seen = true
5251 }
5352 CompositeDecoder .DECODE_DONE -> break @loop // https://youtrack.jetbrains.com/issue/KT-42262
54- else -> throw UnknownFieldException (elementIndex)
53+ else -> throwUnknownIndexException (elementIndex)
5554 }
5655 }
5756 }
5857 }
59- if (! seen) throw MissingFieldException (" nanoseconds" )
58+ if (! seen) throw MissingFieldException (missingField = " nanoseconds" , serialName = descriptor.serialName )
6059 return DateTimeUnit .TimeBased (nanoseconds)
6160 }
6261}
@@ -70,7 +69,7 @@ public object DayBasedDateTimeUnitSerializer: KSerializer<DateTimeUnit.DayBased>
7069
7170 // https://youtrack.jetbrains.com/issue/KT-63939
7271 override val descriptor: SerialDescriptor by lazy(LazyThreadSafetyMode .PUBLICATION ) {
73- buildClassSerialDescriptor(" DayBased" ) {
72+ buildClassSerialDescriptor(" kotlinx.datetime. DayBased" ) {
7473 element<Int >(" days" )
7574 }
7675 }
@@ -82,7 +81,6 @@ public object DayBasedDateTimeUnitSerializer: KSerializer<DateTimeUnit.DayBased>
8281 }
8382
8483 @OptIn(ExperimentalSerializationApi ::class )
85- @Suppress(" INVISIBLE_MEMBER" ) // to be able to throw `MissingFieldException`
8684 override fun deserialize (decoder : Decoder ): DateTimeUnit .DayBased {
8785 var seen = false
8886 var days = 0
@@ -98,12 +96,12 @@ public object DayBasedDateTimeUnitSerializer: KSerializer<DateTimeUnit.DayBased>
9896 seen = true
9997 }
10098 CompositeDecoder .DECODE_DONE -> break @loop // https://youtrack.jetbrains.com/issue/KT-42262
101- else -> throw UnknownFieldException (elementIndex)
99+ else -> throwUnknownIndexException (elementIndex)
102100 }
103101 }
104102 }
105103 }
106- if (! seen) throw MissingFieldException (" days" )
104+ if (! seen) throw MissingFieldException (missingField = " days" , serialName = descriptor.serialName )
107105 return DateTimeUnit .DayBased (days)
108106 }
109107}
@@ -117,7 +115,7 @@ public object MonthBasedDateTimeUnitSerializer: KSerializer<DateTimeUnit.MonthBa
117115
118116 // https://youtrack.jetbrains.com/issue/KT-63939
119117 override val descriptor: SerialDescriptor by lazy(LazyThreadSafetyMode .PUBLICATION ) {
120- buildClassSerialDescriptor(" MonthBased" ) {
118+ buildClassSerialDescriptor(" kotlinx.datetime. MonthBased" ) {
121119 element<Int >(" months" )
122120 }
123121 }
@@ -129,7 +127,6 @@ public object MonthBasedDateTimeUnitSerializer: KSerializer<DateTimeUnit.MonthBa
129127 }
130128
131129 @OptIn(ExperimentalSerializationApi ::class )
132- @Suppress(" INVISIBLE_MEMBER" ) // to be able to throw `MissingFieldException`
133130 override fun deserialize (decoder : Decoder ): DateTimeUnit .MonthBased {
134131 var seen = false
135132 var months = 0
@@ -145,12 +142,12 @@ public object MonthBasedDateTimeUnitSerializer: KSerializer<DateTimeUnit.MonthBa
145142 seen = true
146143 }
147144 CompositeDecoder .DECODE_DONE -> break @loop // https://youtrack.jetbrains.com/issue/KT-42262
148- else -> throw UnknownFieldException (elementIndex)
145+ else -> throwUnknownIndexException (elementIndex)
149146 }
150147 }
151148 }
152149 }
153- if (! seen) throw MissingFieldException (" months" )
150+ if (! seen) throw MissingFieldException (missingField = " months" , serialName = descriptor.serialName )
154151 return DateTimeUnit .MonthBased (months)
155152 }
156153}
@@ -160,7 +157,7 @@ public object MonthBasedDateTimeUnitSerializer: KSerializer<DateTimeUnit.MonthBa
160157 *
161158 * JSON example: `{"type":"DayBased","days":15}`
162159 */
163- @Suppress(" EXPERIMENTAL_API_USAGE_ERROR " , " INVISIBLE_MEMBER " )
160+ @Suppress(" INVISIBLE_MEMBER " , " INVISIBLE_REFERENCE " ) // https://github.com/Kotlin/kotlinx.serialization/issues/2460
164161@OptIn(InternalSerializationApi ::class )
165162public object DateBasedDateTimeUnitSerializer: AbstractPolymorphicSerializer<DateTimeUnit.DateBased>() {
166163
@@ -197,9 +194,9 @@ public object DateBasedDateTimeUnitSerializer: AbstractPolymorphicSerializer<Dat
197194 *
198195 * JSON example: `{"type":"MonthBased","days":15}`
199196 */
200- @Suppress(" EXPERIMENTAL_API_USAGE_ERROR " , " INVISIBLE_MEMBER " )
197+ @Suppress(" INVISIBLE_MEMBER " , " INVISIBLE_REFERENCE " ) // https://github.com/Kotlin/kotlinx.serialization/issues/2460
201198@OptIn(InternalSerializationApi ::class )
202- public object DateTimeUnitSerializer: AbstractPolymorphicSerializer<DateTimeUnit>() {
199+ public object DateTimeUnitSerializer : AbstractPolymorphicSerializer<DateTimeUnit>() {
203200
204201 // https://youtrack.jetbrains.com/issue/KT-63939
205202 private val impl by lazy(LazyThreadSafetyMode .PUBLICATION ) {
@@ -224,4 +221,8 @@ public object DateTimeUnitSerializer: AbstractPolymorphicSerializer<DateTimeUnit
224221 override val descriptor: SerialDescriptor
225222 get() = impl.descriptor
226223
227- }
224+ }
225+
226+ internal fun throwUnknownIndexException (index : Int ): Nothing {
227+ throw SerializationException (" An unknown field for index $index " )
228+ }
0 commit comments