Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change core annotations retention: #1083

Merged
merged 1 commit into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>())
}
}