Skip to content

Commit

Permalink
Change core annotations retention:
Browse files Browse the repository at this point in the history
    * SerialInfo, Transient, Required: binary -> runtime
    * Contextual: runtime -> binary

Fixes #1081
  • Loading branch information
qwwdfsad committed Sep 17, 2020
1 parent 608cbad commit b5b1371
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
8 changes: 5 additions & 3 deletions core/commonMain/src/kotlinx/serialization/Annotations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,22 @@ 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

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

/**
Expand Down Expand Up @@ -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

/**
Expand All @@ -176,6 +177,7 @@ public annotation class Contextual
* @see ContextSerializer
*/
@Target(AnnotationTarget.FILE)
@Retention(AnnotationRetention.BINARY)
public annotation class UseContextualSerialization(vararg val forClasses: KClass<*>)

/**
Expand Down
18 changes: 18 additions & 0 deletions core/jvmTest/src/kotlinx/serialization/RetentionTest.kt
Original file line number Diff line number Diff line change
@@ -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<SerialName>()?.value)
assertNotNull(F::b.findAnnotation<Transient>())
assertNotNull(F::c.findAnnotation<Required>())
}
}

0 comments on commit b5b1371

Please sign in to comment.