kotlinx.serialization: serializer() throws SerializationException when used with sealed class on JS
I have a sealed class Trait in common code:
@Serializable
sealed class Trait() {
abstract val name: String
...
}
I want to get it’s serializer via serializer<Trait>(). On JVM this works fine and I get a SealedClassSerializer. On JS (IR) I get:
"SerializationException: Serializer for class 'Trait' is not found.
Mark the class as @Serializable or provide the serializer explicitly.
On Kotlin/JS explicitly declared serializer should be used for interfaces and enums without @Serializable annotation
at platformSpecificSerializerNotRegistered (http://localhost:8080/static/spellbook.js:159984:11)
at serializer (http://localhost:8080/static/spellbook.js:155641:7)
at main (http://localhost:8080/static/spellbook.js:188469:25)
at Object.<anonymous> (http://localhost:8080/static/spellbook.js:195282:3)
at http://localhost:8080/static/spellbook.js:136257:37
at Object.<anonymous> (http://localhost:8080/static/spellbook.js:136260:2)
at Object.H:\Google Drive\My Stuff\spellbook\build\js\packages\spellbook\kotlin\spellbook.js (http://localhost:8080/static/spellbook.js:195286:30)
at __webpack_require__ (http://localhost:8080/static/spellbook.js:30:30)
at Object.0 (http://localhost:8080/static/spellbook.js:106:18)
at __webpack_require__ (http://localhost:8080/static/spellbook.js:30:30)
at http://localhost:8080/static/spellbook.js:94:18
at http://localhost:8080/static/spellbook.js:97:10
at webpackUniversalModuleDefinition (http://localhost:8080/static/spellbook.js:9:23)
at http://localhost:8080/static/spellbook.js:10:3"
This is with 1.0.0-RC2.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 16 (5 by maintainers)
Commits related to this issue
- Use SerializerFactory interface and generate function for sealed and abstract serializable classes. Fixes https://github.com/Kotlin/kotlinx.serialization/issues/1116 Fixes https://github.com/Kotlin/k... — committed to JetBrains/kotlin by sandwwraith 3 years ago
- Use SerializerFactory interface and generate function for sealed and abstract serializable classes. Fixes https://github.com/Kotlin/kotlinx.serialization/issues/1116 Fixes https://github.com/Kotlin/k... — committed to JetBrains/kotlin by sandwwraith 3 years ago
- Use SerializerFactory interface and generate function for sealed and abstract serializable classes. Fixes https://github.com/Kotlin/kotlinx.serialization/issues/1116 Fixes https://github.com/Kotlin/k... — committed to JetBrains/kotlin by sandwwraith 3 years ago
I’m encountering the same issue with the IR compiler. If I switch to LEGACY, it works fine. Doing the test via JVM is also fine.
build.gradle.kts:
AccessibleRegionsRequest.kt:
AccessibleRegionsTest.kt:
Test Output: