Description
Describe the bug
descriptor.serialName
as per the docs should return the overridden @SerialName
for that field/type, but doesn't seem to respect that.
For generated and default serializers, the serial name is equal to the corresponding class's fully qualified name or, if overridden,
SerialName
To Reproduce
@Serializable
data class TestClass {
@SerialName("notField")
val field: String,
}
assertTrue(TestClass::serializer().getElementDescriptor(0).serialName == "notField") // fails
Unless I'm missing something, it seems impossible to get the annotated @SerialName
from the descriptor at runtime.
(Semi related, it's also impossible to find the correct element descriptor at runtime as you can't reverse lookup by elementName)
Expected behavior
Not sure if serialName
is returning the wrong thing? But ideally I should return notField
as per the docs for val field
.
If that is expected behavior, then the docs need updating. And we need a method to actually get that @SerialName
.
Environment
- Kotlin version: [e.g. 1.3.30] 2.1.10
- Library version: [e.g. 0.11.0] 1.8.0
- Kotlin platforms: [e.g. JVM, JS, Native or their combinations] All
- Gradle version: [e.g. 4.10] 8.13 (but any version)
I have more examples I can share, Sqkon uses this heavily