Skip to content

Not all Repeatable SerialInfo annotation instances make it into the Descriptor #2099

Closed
@bjsvedin

Description

If you create a Repeatable annotation marked with SerialInfo, and then you use it multiple times on a class, only the last instance of that annotation is available on the descriptors annotation property.

To Reproduce

@SerialInfo
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.CLASS)
@Repeatable
annotation class RepeatableSerialInfo(val value: String)

@Serializable
@RepeatableSerialInfo("Value 1")
@RepeatableSerialInfo("Value 2")
@RepeatableSerialInfo("Value 3")
data class RepeatableSerialInfoClass(
    val name:String = "Some Name"
)

class RepeatableSerialInfoTests{

    @Suppress("UNCHECKED_CAST")
    @OptIn(ExperimentalSerializationApi::class)
    @Test
    fun testRepeatableSerialInfo(){
        val serializer = Json.serializersModule.serializer(typeOf<RepeatableSerialInfoClass>()) as KSerializer<RepeatableSerialInfoClass>
        val descriptor = serializer.descriptor
        val annotations = descriptor.annotations
        println(annotations)
        annotations.forEach {
            println((it as RepeatableSerialInfo).value)
        }
    }
}

--- Output ---

[com.hcp.RepeatableSerialInfo$Impl@f5c79a6]
Value 3

Expected behavior

The expected behavior is all three RepeatableSerialInfo instances are in the final annotations list, and i can view all three values.

Environment

  • Kotlin version: 1.7.21
  • Library version: 1.4.1
  • Kotlin platforms: JVM
  • Gradle version: 7.4

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions