Skip to content

Commit 5317f7c

Browse files
authored
Change core annotations retention (#1083)
* SerialInfo, Transient, Required: binary -> runtime * Contextual: runtime -> binary Fixes #1081
1 parent 7dddbe8 commit 5317f7c

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

core/commonMain/src/kotlinx/serialization/Annotations.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,22 @@ public annotation class Serializer(
114114
* ```
115115
*/
116116
@Target(AnnotationTarget.PROPERTY, AnnotationTarget.CLASS)
117-
@Retention(AnnotationRetention.BINARY)
117+
// @Retention(AnnotationRetention.RUNTIME) still runtime, but KT-41082
118118
public annotation class SerialName(val value: String)
119119

120120
/**
121121
* Indicates that property must be present during deserialization process, despite having a default value.
122122
*/
123123
@Target(AnnotationTarget.PROPERTY)
124-
@Retention(AnnotationRetention.BINARY)
124+
// @Retention(AnnotationRetention.RUNTIME) still runtime, but KT-41082
125125
public annotation class Required
126126

127127
/**
128128
* Marks this property invisible for the whole serialization process, including [serial descriptors][SerialDescriptor].
129129
* Transient properties should have default values.
130130
*/
131131
@Target(AnnotationTarget.PROPERTY)
132-
@Retention(AnnotationRetention.BINARY)
132+
// @Retention(AnnotationRetention.RUNTIME) still runtime, but KT-41082
133133
public annotation class Transient
134134

135135
/**
@@ -167,6 +167,7 @@ public annotation class ContextualSerialization(vararg val forClasses: KClass<*>
167167
* @see UseContextualSerialization
168168
*/
169169
@Target(AnnotationTarget.PROPERTY, AnnotationTarget.TYPE)
170+
@Retention(AnnotationRetention.BINARY)
170171
public annotation class Contextual
171172

172173
/**
@@ -176,6 +177,7 @@ public annotation class Contextual
176177
* @see ContextSerializer
177178
*/
178179
@Target(AnnotationTarget.FILE)
180+
@Retention(AnnotationRetention.BINARY)
179181
public annotation class UseContextualSerialization(vararg val forClasses: KClass<*>)
180182

181183
/**
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package kotlinx.serialization
2+
3+
import org.junit.Test
4+
import kotlin.reflect.full.*
5+
import kotlin.test.*
6+
7+
class RetentionTest {
8+
9+
@Serializable
10+
class F(@SerialName("?") val a: Int, @Transient val b: Int = 42, @Required val c: Int)
11+
12+
@Test
13+
fun testRetention() {
14+
assertEquals("?", F::a.findAnnotation<SerialName>()?.value)
15+
assertNotNull(F::b.findAnnotation<Transient>())
16+
assertNotNull(F::c.findAnnotation<Required>())
17+
}
18+
}

0 commit comments

Comments
 (0)