1
1
/*
2
- * Copyright 2019-2021 JetBrains s.r.o.
2
+ * Copyright 2019-2023 JetBrains s.r.o.
3
3
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
4
4
*/
5
5
@@ -23,7 +23,7 @@ public object TimeBasedDateTimeUnitSerializer: KSerializer<DateTimeUnit.TimeBase
23
23
24
24
// https://youtrack.jetbrains.com/issue/KT-63939
25
25
override val descriptor: SerialDescriptor by lazy(LazyThreadSafetyMode .PUBLICATION ) {
26
- buildClassSerialDescriptor(" TimeBased" ) {
26
+ buildClassSerialDescriptor(" kotlinx.datetime. TimeBased" ) {
27
27
element<Long >(" nanoseconds" )
28
28
}
29
29
}
@@ -35,7 +35,6 @@ public object TimeBasedDateTimeUnitSerializer: KSerializer<DateTimeUnit.TimeBase
35
35
}
36
36
37
37
@OptIn(ExperimentalSerializationApi ::class )
38
- @Suppress(" INVISIBLE_MEMBER" ) // to be able to throw `MissingFieldException`
39
38
override fun deserialize (decoder : Decoder ): DateTimeUnit .TimeBased {
40
39
var seen = false
41
40
var nanoseconds = 0L
@@ -51,12 +50,12 @@ public object TimeBasedDateTimeUnitSerializer: KSerializer<DateTimeUnit.TimeBase
51
50
seen = true
52
51
}
53
52
CompositeDecoder .DECODE_DONE -> break @loop // https://youtrack.jetbrains.com/issue/KT-42262
54
- else -> throw UnknownFieldException (elementIndex)
53
+ else -> throwUnknownIndexException (elementIndex)
55
54
}
56
55
}
57
56
}
58
57
}
59
- if (! seen) throw MissingFieldException (" nanoseconds" )
58
+ if (! seen) throw MissingFieldException (missingField = " nanoseconds" , serialName = descriptor.serialName )
60
59
return DateTimeUnit .TimeBased (nanoseconds)
61
60
}
62
61
}
@@ -70,7 +69,7 @@ public object DayBasedDateTimeUnitSerializer: KSerializer<DateTimeUnit.DayBased>
70
69
71
70
// https://youtrack.jetbrains.com/issue/KT-63939
72
71
override val descriptor: SerialDescriptor by lazy(LazyThreadSafetyMode .PUBLICATION ) {
73
- buildClassSerialDescriptor(" DayBased" ) {
72
+ buildClassSerialDescriptor(" kotlinx.datetime. DayBased" ) {
74
73
element<Int >(" days" )
75
74
}
76
75
}
@@ -82,7 +81,6 @@ public object DayBasedDateTimeUnitSerializer: KSerializer<DateTimeUnit.DayBased>
82
81
}
83
82
84
83
@OptIn(ExperimentalSerializationApi ::class )
85
- @Suppress(" INVISIBLE_MEMBER" ) // to be able to throw `MissingFieldException`
86
84
override fun deserialize (decoder : Decoder ): DateTimeUnit .DayBased {
87
85
var seen = false
88
86
var days = 0
@@ -98,12 +96,12 @@ public object DayBasedDateTimeUnitSerializer: KSerializer<DateTimeUnit.DayBased>
98
96
seen = true
99
97
}
100
98
CompositeDecoder .DECODE_DONE -> break @loop // https://youtrack.jetbrains.com/issue/KT-42262
101
- else -> throw UnknownFieldException (elementIndex)
99
+ else -> throwUnknownIndexException (elementIndex)
102
100
}
103
101
}
104
102
}
105
103
}
106
- if (! seen) throw MissingFieldException (" days" )
104
+ if (! seen) throw MissingFieldException (missingField = " days" , serialName = descriptor.serialName )
107
105
return DateTimeUnit .DayBased (days)
108
106
}
109
107
}
@@ -117,7 +115,7 @@ public object MonthBasedDateTimeUnitSerializer: KSerializer<DateTimeUnit.MonthBa
117
115
118
116
// https://youtrack.jetbrains.com/issue/KT-63939
119
117
override val descriptor: SerialDescriptor by lazy(LazyThreadSafetyMode .PUBLICATION ) {
120
- buildClassSerialDescriptor(" MonthBased" ) {
118
+ buildClassSerialDescriptor(" kotlinx.datetime. MonthBased" ) {
121
119
element<Int >(" months" )
122
120
}
123
121
}
@@ -129,7 +127,6 @@ public object MonthBasedDateTimeUnitSerializer: KSerializer<DateTimeUnit.MonthBa
129
127
}
130
128
131
129
@OptIn(ExperimentalSerializationApi ::class )
132
- @Suppress(" INVISIBLE_MEMBER" ) // to be able to throw `MissingFieldException`
133
130
override fun deserialize (decoder : Decoder ): DateTimeUnit .MonthBased {
134
131
var seen = false
135
132
var months = 0
@@ -145,12 +142,12 @@ public object MonthBasedDateTimeUnitSerializer: KSerializer<DateTimeUnit.MonthBa
145
142
seen = true
146
143
}
147
144
CompositeDecoder .DECODE_DONE -> break @loop // https://youtrack.jetbrains.com/issue/KT-42262
148
- else -> throw UnknownFieldException (elementIndex)
145
+ else -> throwUnknownIndexException (elementIndex)
149
146
}
150
147
}
151
148
}
152
149
}
153
- if (! seen) throw MissingFieldException (" months" )
150
+ if (! seen) throw MissingFieldException (missingField = " months" , serialName = descriptor.serialName )
154
151
return DateTimeUnit .MonthBased (months)
155
152
}
156
153
}
@@ -160,7 +157,7 @@ public object MonthBasedDateTimeUnitSerializer: KSerializer<DateTimeUnit.MonthBa
160
157
*
161
158
* JSON example: `{"type":"DayBased","days":15}`
162
159
*/
163
- @Suppress(" EXPERIMENTAL_API_USAGE_ERROR " , " INVISIBLE_MEMBER " )
160
+ @Suppress(" INVISIBLE_MEMBER " , " INVISIBLE_REFERENCE " ) // https://github.com/Kotlin/kotlinx.serialization/issues/2460
164
161
@OptIn(InternalSerializationApi ::class )
165
162
public object DateBasedDateTimeUnitSerializer: AbstractPolymorphicSerializer<DateTimeUnit.DateBased>() {
166
163
@@ -197,9 +194,9 @@ public object DateBasedDateTimeUnitSerializer: AbstractPolymorphicSerializer<Dat
197
194
*
198
195
* JSON example: `{"type":"MonthBased","days":15}`
199
196
*/
200
- @Suppress(" EXPERIMENTAL_API_USAGE_ERROR " , " INVISIBLE_MEMBER " )
197
+ @Suppress(" INVISIBLE_MEMBER " , " INVISIBLE_REFERENCE " ) // https://github.com/Kotlin/kotlinx.serialization/issues/2460
201
198
@OptIn(InternalSerializationApi ::class )
202
- public object DateTimeUnitSerializer: AbstractPolymorphicSerializer<DateTimeUnit>() {
199
+ public object DateTimeUnitSerializer : AbstractPolymorphicSerializer<DateTimeUnit>() {
203
200
204
201
// https://youtrack.jetbrains.com/issue/KT-63939
205
202
private val impl by lazy(LazyThreadSafetyMode .PUBLICATION ) {
@@ -224,4 +221,8 @@ public object DateTimeUnitSerializer: AbstractPolymorphicSerializer<DateTimeUnit
224
221
override val descriptor: SerialDescriptor
225
222
get() = impl.descriptor
226
223
227
- }
224
+ }
225
+
226
+ internal fun throwUnknownIndexException (index : Int ): Nothing {
227
+ throw SerializationException (" An unknown field for index $index " )
228
+ }
0 commit comments