All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.kotlinx.serialization.Migrations.kt Maven / Gradle / Ivy

The newest version!
/*
 * 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.descriptors.*
import kotlinx.serialization.encoding.*
import kotlinx.serialization.internal.*
import kotlinx.serialization.modules.*
import kotlin.internal.*
import kotlin.reflect.*

@PublishedApi
internal 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  KSerializer.nullable: KSerializer
    get() {
        @Suppress("UNCHECKED_CAST")
        return if (descriptor.isNullable) (this as KSerializer) 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  KSerializer.list: KSerializer>
    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  KSerializer.set: KSerializer>
    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  Pair, KSerializer>.map: KSerializer>
    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  KClass.compiledSerializer(): KSerializer? = 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  StringFormat.parseList(objects: String): List =
    decodeFromString(ListSerializer(serializersModule.getContextualOrDefault()), objects)

@Deprecated(
    level = DeprecationLevel.WARNING,
    message = "Use default decodeFromString overload instead",
    replaceWith = ReplaceWith("decodeFromString(map)")
)
public inline fun  StringFormat.parseMap(map: String): Map =
    decodeFromString(MapSerializer(serializersModule.getContextualOrDefault(), serializersModule.getContextualOrDefault()), 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  StringFormat.stringify(objects: List): String =
    encodeToString(ListSerializer(serializersModule.getContextualOrDefault()), objects)

@LowPriorityInOverloadResolution
@Deprecated(
    level = DeprecationLevel.ERROR,
    message = "Use default stringify overload instead",
    replaceWith = ReplaceWith("stringify(map)")
)
public inline fun  StringFormat.stringify(map: Map): String =
    encodeToString(MapSerializer(serializersModule.getContextualOrDefault(), serializersModule.getContextualOrDefault()), map)

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

@ImplicitReflectionSerializer
@OptIn(UnsafeSerializationApi::class)
@Deprecated(
    level = DeprecationLevel.WARNING,
    message = "This method is deprecated for removal. Please use reified getContextualOrDefault() instead",
    replaceWith = ReplaceWith("getContextualOrDefault()")
)
public fun  SerializersModule.getContextualOrDefault(value: T): KSerializer =
    getContextual(value::class)?.cast() ?: 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 serializersModule: SerializersModule) : SerialFormat

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

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

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

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

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

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

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

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

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

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

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

@Deprecated(
    "This method was renamed to decodeFromHexString during serialization 1.0 stabilization",
    ReplaceWith("decodeFromHexString(hex)"), DeprecationLevel.ERROR
)
public fun  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  Decoder.decode(deserializer: DeserializationStrategy): T = noImpl()

@Deprecated(
    "This method was deprecated during serialization 1.0 API stabilization",
    ReplaceWith("decodeSerializableValue(serializer())"), DeprecationLevel.ERROR
) // TODO make internal when migrations are removed
public fun  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  Encoder.encode(strategy: SerializationStrategy, value: T): Unit = noImpl()

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

@Deprecated(
    "This method was renamed to buildClassSerialDescriptor during serialization 1.0 API stabilization",
    replaceWith = ReplaceWith(
        "buildClassSerialDescriptor(serialName, *typeParameters, builderAction)",
        imports = ["kotlinx.serialization.descriptors.buildClassSerialDescriptor"]
    ),
    DeprecationLevel.ERROR
)
public fun SerialDescriptor(
    serialName: String,
    vararg typeParameters: SerialDescriptor,
    builderAction: ClassSerialDescriptorBuilder.() -> Unit = {}
): SerialDescriptor = noImpl()

@Deprecated(
    "Builder with SerialKind was deprecated during serialization 1.0 API stabilization. ",
    replaceWith = ReplaceWith(
        "buildSerialDescriptor(serialName, kind, *typeParameters, builderAction)",
        imports = ["kotlinx.serialization.descriptors.buildSerialDescriptor"]
    ),
    DeprecationLevel.ERROR
)
public fun SerialDescriptor(
    serialName: String,
    kind: SerialKind,
    vararg typeParameters: SerialDescriptor,
    builderAction: ClassSerialDescriptorBuilder.() -> Unit = {}
): SerialDescriptor = noImpl()

@Deprecated(
    "This method was renamed to PrimitiveSerialDescriptor during serialization 1.0 API stabilization",
    ReplaceWith(
        "PrimitiveSerialDescriptor(serialName, kind)",
        imports = ["kotlinx.serialization.descriptors.PrimitiveSerialDescriptor"]
    ),
    DeprecationLevel.ERROR
)
public fun PrimitiveDescriptor(serialName: String, kind: PrimitiveKind): SerialDescriptor = noImpl()

@Deprecated(
    "This property was renamed to serializersModule during serialization 1.0 stabilization",
    ReplaceWith("serializersModule"), DeprecationLevel.ERROR
)
public val SerialFormat.context: SerializersModule
    get() = noImpl()

@Deprecated(
    "This method was replaced with property during serialization 1.0 stabilization",
    ReplaceWith("elementDescriptors.toList()",
        imports = ["kotlinx.serialization.descriptors.elementNames"]
    ), DeprecationLevel.ERROR
)
public fun SerialDescriptor.elementDescriptors(): List = noImpl()

@Deprecated(
    "This method was replaced with property during serialization 1.0 stabilization",
    ReplaceWith(
        "elementNames.toList()",
        imports = ["kotlinx.serialization.descriptors.elementNames"]
    ), DeprecationLevel.ERROR
)
public fun SerialDescriptor.elementNames(): List = noImpl()


@RequiresOptIn
@Deprecated(level = DeprecationLevel.ERROR, message = "This annotation is obsolete and deprecated for removal")
public annotation class ImplicitReflectionSerializer

@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
@Deprecated(
    level = DeprecationLevel.ERROR,
    message = "Deprecated for removal during serialization 1.0 API stabilization")
public annotation class UnstableDefault




© 2015 - 2025 Weber Informatics LLC | Privacy Policy