summaryrefslogtreecommitdiff
path: root/runtime/commonMain/src/kotlinx/serialization/Migrations.kt
blob: 54b8a822089e75e8146f6d3cd6a04b5727601dfe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/*
 * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
 */
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "UNUSED", "UNUSED_PARAMETER", "DEPRECATION_ERROR")
package kotlinx.serialization

import kotlinx.serialization.builtins.*
import kotlinx.serialization.encoding.*
import kotlinx.serialization.internal.*
import kotlinx.serialization.modules.*
import kotlin.internal.*
import kotlin.reflect.*

private fun noImpl(): Nothing = throw UnsupportedOperationException("Not implemented, should not be called")

@Deprecated(
    message = "Deprecated in the favour of PrimitiveDescriptor factory function",
    level = DeprecationLevel.ERROR
)
public class PrimitiveDescriptorWithName
@Deprecated(
    message = "Deprecated in the favour of PrimitiveDescriptor factory function",
    level = DeprecationLevel.ERROR,
    replaceWith = ReplaceWith("PrimitiveDescriptor(name, original.kind)")
)
constructor(override val serialName: String, private val original: SerialDescriptor) : SerialDescriptor by original

@Deprecated(
    message = "Deprecated in the favour of PrimitiveDescriptor factory function",
    level = DeprecationLevel.ERROR,
    replaceWith = ReplaceWith("PrimitiveDescriptor(name, this.kind)")
)
public fun SerialDescriptor.withName(name: String): SerialDescriptor = error("No longer supported")

@Deprecated(level = DeprecationLevel.ERROR,
    message = "Deprecated in the favour of the same extension from builtins package",
    replaceWith = ReplaceWith("nullable", imports = ["kotlinx.serialization.builtins.nullable"]))
@LowPriorityInOverloadResolution
public val <T : Any> KSerializer<T>.nullable: KSerializer<T?>
    get() {
        @Suppress("UNCHECKED_CAST")
        return if (descriptor.isNullable) (this as KSerializer<T?>) else NullableSerializer(this)
    }

@Deprecated(
    level = DeprecationLevel.ERROR,
    message = "Deprecated in the favour of the same extension from builtins package",
    replaceWith = ReplaceWith("list", imports = ["kotlinx.serialization.builtins.list"])
)
@LowPriorityInOverloadResolution
public val <T> KSerializer<T>.list: KSerializer<List<T>>
    get() = ArrayListSerializer(this)

@Deprecated(
    level = DeprecationLevel.ERROR,
    message = "Deprecated in the favour of the same extension from builtins package",
    replaceWith = ReplaceWith("set", imports = ["kotlinx.serialization.builtins.set"])
)
@LowPriorityInOverloadResolution
public val <T> KSerializer<T>.set: KSerializer<Set<T>>
    get() = LinkedHashSetSerializer(this)

@Deprecated(
    level = DeprecationLevel.ERROR, message = "Deprecated in the favour of the MapSerializer() factory function",
    replaceWith = ReplaceWith(
        "MapSerializer(this.first, this.second)",
        imports = ["kotlinx.serialization.builtins.MapSerializer"]
    )
)
public val <K, V> Pair<KSerializer<K>, KSerializer<V>>.map: KSerializer<Map<K, V>>
    get() = LinkedHashMapSerializer(this.first, this.second)

@Deprecated(
    "Renamed to AbstractEncoder",
    replaceWith = ReplaceWith("AbstractEncoder", imports = ["kotlinx.serialization.encoding.AbstractEncoder"])
)
public typealias ElementValueEncoder = AbstractEncoder

@Deprecated(
    "Renamed to AbstractDecoder",
    replaceWith = ReplaceWith("AbstractDecoder", imports = ["kotlinx.serialization.encoding.AbstractDecoder"])
)
public typealias ElementValueDecoder = AbstractDecoder

@Deprecated(
    "This function accidentally slipped to a public API surface and is not intended for public use " +
            "since it does not have clear specification.",
    ReplaceWith("serializerOrNull"),
    level = DeprecationLevel.ERROR
)
public fun <T : Any> KClass<T>.compiledSerializer(): KSerializer<T>? = compiledSerializerImpl()

private const val message =
    "Mapper was renamed to Properties to better reflect its semantics and extracted to separate artifact kotlinx-serialization-properties"

@Deprecated(message = message, level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("Properties"))
public class Mapper()

@SerialInfo
@Target(AnnotationTarget.PROPERTY)
@Deprecated(
    message = "SerialId is renamed to ProtoId to better reflect its semantics and extracted to separate artifact kotlinx-serialization-protobuf",
    level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("ProtoId", imports = ["kotlinx.serialization.protobuf.*"])
)
public annotation class SerialId @Deprecated(
    message = "SerialId is renamed to ProtoId to better reflect its semantics and extracted to separate artifact kotlinx-serialization-protobuf",
    level = DeprecationLevel.ERROR,
    replaceWith = ReplaceWith("ProtoId(id)", imports = ["kotlinx.serialization.protobuf.*"])
) constructor(public val id: Int)


@Deprecated(level = DeprecationLevel.WARNING, message = "Use default parse overload instead", replaceWith = ReplaceWith("parse(objects)"))
public inline fun <reified T : Any> StringFormat.parseList(objects: String): List<T> =
    decodeFromString(ListSerializer(context.getContextualOrDefault<T>()), objects)

@Deprecated(
    level = DeprecationLevel.WARNING,
    message = "Use default decodeFromString overload instead",
    replaceWith = ReplaceWith("decodeFromString(map)")
)
public inline fun <reified K : Any, reified V : Any> StringFormat.parseMap(map: String): Map<K, V> =
    decodeFromString(MapSerializer(context.getContextualOrDefault<K>(), context.getContextualOrDefault<V>()), map)

// ERROR migrations that affect **only** users that called these functions with named parameters

@LowPriorityInOverloadResolution
@Deprecated(
    level = DeprecationLevel.ERROR,
    message = "Use default encodeToString overload instead",
    replaceWith = ReplaceWith("encodeToString(objects)")
)
public inline fun <reified T : Any> StringFormat.stringify(objects: List<T>): String =
    encodeToString(ListSerializer(context.getContextualOrDefault<T>()), objects)

@LowPriorityInOverloadResolution
@Deprecated(
    level = DeprecationLevel.ERROR,
    message = "Use default stringify overload instead",
    replaceWith = ReplaceWith("stringify(map)")
)
public inline fun <reified K : Any, reified V : Any> StringFormat.stringify(map: Map<K, V>): String =
    encodeToString(MapSerializer(context.getContextualOrDefault<K>(), context.getContextualOrDefault<V>()), map)

@ImplicitReflectionSerializer
@OptIn(UnsafeSerializationApi::class)
@Deprecated(
    level = DeprecationLevel.WARNING,
    message = "This method is deprecated for removal. Please use reified getContextualOrDefault<T>() instead",
    replaceWith = ReplaceWith("getContextual(klass) ?: klass.serializer()")
)
public fun <T : Any> SerialModule.getContextualOrDefault(klass: KClass<T>): KSerializer<T> =
    getContextual(klass) ?: klass.serializer()

@ImplicitReflectionSerializer
@OptIn(UnsafeSerializationApi::class)
@Deprecated(
    level = DeprecationLevel.WARNING,
    message = "This method is deprecated for removal. Please use reified getContextualOrDefault<T>() instead",
    replaceWith = ReplaceWith("getContextualOrDefault<T>()")
)
public fun <T : Any> SerialModule.getContextualOrDefault(value: T): KSerializer<T> =
    getContextual(value) ?: value::class.serializer().cast()

@Suppress("UNUSED", "DeprecatedCallableAddReplaceWith")
@Deprecated(
    message = "Top-level polymorphic descriptor is deprecated, use descriptor from the instance of PolymorphicSerializer or" +
            "check for descriptor kind instead", level = DeprecationLevel.ERROR
)
public val PolymorphicClassDescriptor: SerialDescriptor
    get() = error("This property is no longer supported")

@Deprecated(
    "Deprecated for removal since it is indistinguishable from SerialFormat interface. " +
            "Use SerialFormat instead.", ReplaceWith("SerialFormat"), DeprecationLevel.ERROR
)
public abstract class AbstractSerialFormat(override val context: SerialModule) : SerialFormat

@Deprecated(
    "This method was renamed to encodeToString during serialization 1.0 stabilization",
    ReplaceWith("encodeToString<T>(value)"), DeprecationLevel.ERROR
)
public fun <T : Any> StringFormat.stringify(value: T): String = noImpl()

@Deprecated(
    "This method was renamed to decodeFromString during serialization 1.0 stabilization",
    ReplaceWith("decodeFromString<T>(string)"), DeprecationLevel.ERROR
)
public fun <T : Any> StringFormat.parse(string: String): T = noImpl()

@Deprecated(
    "This method was renamed to encodeToString during serialization 1.0 stabilization",
    ReplaceWith("encodeToString<T>(serializer, value)"), DeprecationLevel.ERROR
)
public fun <T> StringFormat.stringify(serializer: SerializationStrategy<T>, value: T): String = noImpl()

@Deprecated(
    "This method was renamed to decodeFromString during serialization 1.0 stabilization",
    ReplaceWith("decodeFromString<T>(deserializer, string)"), DeprecationLevel.ERROR
)
public fun <T> StringFormat.parse(deserializer: DeserializationStrategy<T>, string: String): T = noImpl()

@Deprecated(
    "This method was renamed to decodeFromByteArray during serialization 1.0 stabilization",
    ReplaceWith("decodeFromByteArray<T>(deserializer, bytes)"), DeprecationLevel.ERROR
)
public fun <T> BinaryFormat.load(deserializer: DeserializationStrategy<T>, bytes: ByteArray): T = noImpl()

@Deprecated(
    "This method was renamed to encodeToByteArray during serialization 1.0 stabilization",
    ReplaceWith("encodeToByteArray<T>(serializer, value)"), DeprecationLevel.ERROR
)
public fun <T> BinaryFormat.dump(serializer: SerializationStrategy<T>, value: T): ByteArray = noImpl()

@Deprecated(
    "This method was renamed to encodeToHexString during serialization 1.0 stabilization",
    ReplaceWith("encodeToHexString<T>(serializer, value)"), DeprecationLevel.ERROR
)
public fun <T> BinaryFormat.dumps(serializer: SerializationStrategy<T>, value: T): String = noImpl()

@Deprecated(
    "This method was renamed to decodeFromHexString during serialization 1.0 stabilization",
    ReplaceWith("decodeFromHexString<T>(deserializer, hex)"), DeprecationLevel.ERROR
)
public fun <T> BinaryFormat.loads(deserializer: DeserializationStrategy<T>, hex: String): T = noImpl()

@Deprecated(
    "This method was renamed to encodeToByteArray during serialization 1.0 stabilization",
    ReplaceWith("encodeToByteArray<T>(value)"), DeprecationLevel.ERROR
)
public fun <T : Any> BinaryFormat.dump(value: T): ByteArray = noImpl()

@Deprecated(
    "This method was renamed to encodeToHexString during serialization 1.0 stabilization",
    ReplaceWith("encodeToHexString<T>(value)"), DeprecationLevel.ERROR
)
public fun <T : Any> BinaryFormat.dumps(value: T): String = noImpl()

@Deprecated(
    "This method was renamed to decodeFromByteArray during serialization 1.0 stabilization",
    ReplaceWith("this.decodeFromByteArray<T>(raw)"), DeprecationLevel.ERROR
)
public fun <T : Any> BinaryFormat.load(raw: ByteArray): T = noImpl()

@Deprecated(
    "This method was renamed to decodeFromHexString during serialization 1.0 stabilization",
    ReplaceWith("decodeFromHexString<T>(hex)"), DeprecationLevel.ERROR
)
public fun <T : Any> BinaryFormat.loads(hex: String): T = noImpl()

@Deprecated(
    "This method was deprecated during serialization 1.0 API stabilization",
    ReplaceWith("decodeSerializableValue(deserializer)"), DeprecationLevel.ERROR
) // TODO make internal when migrations are removed
public fun <T : Any?> Decoder.decode(deserializer: DeserializationStrategy<T>): T = noImpl()

@Deprecated(
    "This method was deprecated during serialization 1.0 API stabilization",
    ReplaceWith("decodeSerializableValue<T>(serializer())"), DeprecationLevel.ERROR
) // TODO make internal when migrations are removed
public fun <T : Any> Decoder.decode(): T = noImpl()

@Deprecated(
    "This method was deprecated during serialization 1.0 API stabilization",
    ReplaceWith("encodeSerializableValue(strategy, value)"), DeprecationLevel.ERROR
) // TODO make internal when migrations are removed
public fun <T : Any?> Encoder.encode(strategy: SerializationStrategy<T>, value: T): Unit = noImpl()

@Deprecated(
    "This method was deprecated during serialization 1.0 API stabilization",
    ReplaceWith("encodeSerializableValue<T>(serializer(), value)"), DeprecationLevel.ERROR
) // TODO make internal when migrations are removed
public fun <T : Any> Encoder.encode(obj: T): Unit = noImpl()