Hi, I am getting an error and I can't figure out h...
# serialization
j
Hi, I am getting an error and I can't figure out how the default polymorphic serializer is messing it up:
kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 26: Expected '[, kind: SEALED'
Any help is appreciated.
The issue occurs in an MPP app when a post is done from JS to server
all the types are in a sealed class hierarchy. Though they are not scoped to the root type. IE
Copy code
@Serializable
sealed class Rule

class MyRule : Rule()
r
Did you mark your subclasses as serializable (i.e.
MyRule
)? I'm fairly sure that's required, although I'm not sure why it doesn't show a compiler error.
j
Yes you have to mark all the classes as serializable. I don't think it should show a compiler error, as it simply registers all the serializers somewhere and then at runtime it tries to fetch the serializer for your type, which is missing, and then it simply fails.
j
yes, the entire tree is marked serializable. It serializes in the JVM and in the browser, its in the transfer from the browser to ktor that it fails.
I had to explicitly declare the serializer module. To make this work. This seems really unscalable though. Anyone know if this is supposed to work this way or not?