You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Named companion objects of sealed interfaces do not auto-generate serializers when tagged with @Serializable.
Note that this only occurs when the companion object is named, if unnamed this error will not occur.
To Reproduce
importkotlinx.serialization.SerialNameimportkotlinx.serialization.Serializableimportkotlinx.serialization.encodeToStringimportkotlinx.serialization.json.Json
@Serializable
sealedinterfaceMyInterface {
companionobject NamedCompanionObject {
constvalExample="testing"
}
}
@Serializable
@SerialName("FooBar")
data classFooBar(valvalue:String): MyInterface
funmain() {
// error will be thrown here, reporting that MyInterface is not tagged with @Serializableval text =Json.encodeToString<MyInterface>(FooBar(MyInterface.Example))
println(text)
}
Expected behavior
This should not throw an error, or at least I don't believe it should.
Nothing in the documentation I could find implies this is expected behavior.
Environment
Kotlin version: 1.8.0
Library version: 1.4.1
Kotlin platforms: JVM
Gradle version: 7.4.2
IDE version: Unsure if related but IntelliJ IDEA 2022.2.3
The text was updated successfully, but these errors were encountered:
Describe the bug
Named companion objects of sealed interfaces do not auto-generate serializers when tagged with
@Serializable
.Note that this only occurs when the companion object is named, if unnamed this error will not occur.
To Reproduce
Expected behavior
This should not throw an error, or at least I don't believe it should.
Nothing in the documentation I could find implies this is expected behavior.
Environment
The text was updated successfully, but these errors were encountered: