diff --git a/core/commonMain/src/kotlinx/serialization/Annotations.kt b/core/commonMain/src/kotlinx/serialization/Annotations.kt index cba3f973dc..5a0141ac37 100644 --- a/core/commonMain/src/kotlinx/serialization/Annotations.kt +++ b/core/commonMain/src/kotlinx/serialization/Annotations.kt @@ -114,14 +114,14 @@ public annotation class Serializer( * ``` */ @Target(AnnotationTarget.PROPERTY, AnnotationTarget.CLASS) -@Retention(AnnotationRetention.BINARY) +// @Retention(AnnotationRetention.RUNTIME) still runtime, but KT-41082 public annotation class SerialName(val value: String) /** * Indicates that property must be present during deserialization process, despite having a default value. */ @Target(AnnotationTarget.PROPERTY) -@Retention(AnnotationRetention.BINARY) +// @Retention(AnnotationRetention.RUNTIME) still runtime, but KT-41082 public annotation class Required /** @@ -129,7 +129,7 @@ public annotation class Required * Transient properties should have default values. */ @Target(AnnotationTarget.PROPERTY) -@Retention(AnnotationRetention.BINARY) +// @Retention(AnnotationRetention.RUNTIME) still runtime, but KT-41082 public annotation class Transient /** @@ -167,6 +167,7 @@ public annotation class ContextualSerialization(vararg val forClasses: KClass<*> * @see UseContextualSerialization */ @Target(AnnotationTarget.PROPERTY, AnnotationTarget.TYPE) +@Retention(AnnotationRetention.BINARY) public annotation class Contextual /** @@ -176,6 +177,7 @@ public annotation class Contextual * @see ContextSerializer */ @Target(AnnotationTarget.FILE) +@Retention(AnnotationRetention.BINARY) public annotation class UseContextualSerialization(vararg val forClasses: KClass<*>) /** diff --git a/core/jvmTest/src/kotlinx/serialization/RetentionTest.kt b/core/jvmTest/src/kotlinx/serialization/RetentionTest.kt new file mode 100644 index 0000000000..4c46ef0433 --- /dev/null +++ b/core/jvmTest/src/kotlinx/serialization/RetentionTest.kt @@ -0,0 +1,18 @@ +package kotlinx.serialization + +import org.junit.Test +import kotlin.reflect.full.* +import kotlin.test.* + +class RetentionTest { + + @Serializable + class F(@SerialName("?") val a: Int, @Transient val b: Int = 42, @Required val c: Int) + + @Test + fun testRetention() { + assertEquals("?", F::a.findAnnotation()?.value) + assertNotNull(F::b.findAnnotation()) + assertNotNull(F::c.findAnnotation()) + } +}