Is it expected that the descriptor of an external ...
# serialization
l
Is it expected that the descriptor of an external serializer is incomplete (i.e. it does not have element descriptors despite having elements)? Context in 🧵
Consider the following simple test program:
Copy code
@Serializer(forClass = Foo::class)
private object GeneratedFooSerializer : KSerializer<Foo>

@Serializable
private data class Foo(val bar: String)

private fun main() {
    println(GeneratedFooSerializer.descriptor)
}
This will throw an AIOOB:
Copy code
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
	at kotlinx.serialization.internal.PluginGeneratedSerialDescriptor.getElementDescriptor(PluginGeneratedSerialDescriptor.kt:135)
	at kotlinx.serialization.internal.PluginGeneratedSerialDescriptor$toString$1.invoke(PluginGeneratedSerialDescriptor.kt:101)
	at kotlinx.serialization.internal.PluginGeneratedSerialDescriptor$toString$1.invoke(PluginGeneratedSerialDescriptor.kt:100)
	at kotlin.text.StringsKt__AppendableKt.appendElement(Appendable.kt:85)
	at kotlin.collections.CollectionsKt___CollectionsKt.joinTo(_Collections.kt:3490)
	at kotlin.collections.CollectionsKt___CollectionsKt.joinToString(_Collections.kt:3507)
	at kotlin.collections.CollectionsKt___CollectionsKt.joinToString$default(_Collections.kt:3506)
	at kotlinx.serialization.internal.PluginGeneratedSerialDescriptor.toString(PluginGeneratedSerialDescriptor.kt:100)
	at java.base/java.lang.String.valueOf(String.java:4461)
	at java.base/java.io.PrintStream.println(PrintStream.java:1187)
	at TestKt.main(Test.kt:33)
	at TestKt.main(Test.kt)
Checking
elementsCount
confirms that there is one element.
getElementName
and
getElementAnnotations
work fine but
getElementDescriptor
throws.