summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Shanshin <sergey.shanshin@jetbrains.com>2024-02-13 16:04:37 +0300
committerGitHub <noreply@github.com>2024-02-13 14:04:37 +0100
commita6c4d67afd7bc10dd629542c2b88262f2e74bbb1 (patch)
tree92fc25060e716a0eff23c7267b998a0d444e90cd
parent729fc246e412c160c67873dc24ea345b80d02424 (diff)
downloadkotlinx.serialization-a6c4d67afd7bc10dd629542c2b88262f2e74bbb1.tar.gz
Added annotation to keep generated serializer when a custom one is specified (#2566)
If the @KeepGeneratedSerializer annotation is specified on the class, and a custom serializer is specified, then keep to generate a plugin serializer. Resolves #1169 Co-authored-by: Leonid Startsev <sandwwraith@users.noreply.github.com>
-rw-r--r--core/api/kotlinx-serialization-core.api3
-rw-r--r--core/commonMain/src/kotlinx/serialization/Annotations.kt17
2 files changed, 20 insertions, 0 deletions
diff --git a/core/api/kotlinx-serialization-core.api b/core/api/kotlinx-serialization-core.api
index 4b46dcca..720e5847 100644
--- a/core/api/kotlinx-serialization-core.api
+++ b/core/api/kotlinx-serialization-core.api
@@ -44,6 +44,9 @@ public abstract interface class kotlinx/serialization/KSerializer : kotlinx/seri
public abstract fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
}
+public abstract interface annotation class kotlinx/serialization/KeepGeneratedSerializer : java/lang/annotation/Annotation {
+}
+
public abstract interface annotation class kotlinx/serialization/MetaSerializable : java/lang/annotation/Annotation {
}
diff --git a/core/commonMain/src/kotlinx/serialization/Annotations.kt b/core/commonMain/src/kotlinx/serialization/Annotations.kt
index 67104dc3..081ee827 100644
--- a/core/commonMain/src/kotlinx/serialization/Annotations.kt
+++ b/core/commonMain/src/kotlinx/serialization/Annotations.kt
@@ -325,6 +325,23 @@ public annotation class UseSerializers(vararg val serializerClasses: KClass<out
public annotation class Polymorphic
/**
+ * Instructs the serialization plugin to keep automatically generated implementation of [KSerializer]
+ * for the current class if a custom serializer is specified at the same time `@Serializable(with=SomeSerializer::class)`.
+ *
+ * Automatically generated serializer is available via `generatedSerializer()` function in companion object of serializable class.
+ *
+ * Generated serializers allow to use custom serializers on classes from which other serializable classes are inherited.
+ *
+ * Used only with the [Serializable] annotation.
+ *
+ * A compiler version `2.0.0` and higher is required.
+ */
+@InternalSerializationApi
+@Target(AnnotationTarget.CLASS)
+@Retention(AnnotationRetention.RUNTIME)
+public annotation class KeepGeneratedSerializer
+
+/**
* Marks declarations that are still **experimental** in kotlinx.serialization, which means that the design of the
* corresponding declarations has open issues which may (or may not) lead to their changes in the future.
* Roughly speaking, there is a chance that those declarations will be deprecated in the near future or