I'm getting a `kotlinx.serialization.Serialization...
# getting-started
c
I'm getting a
kotlinx.serialization.SerializationException
but the error doesn't make sense. This is the error:
Copy code
Exception in thread "main" kotlinx.serialization.SerializationException: Serializer for subclass 'GridClueSelection' is not found in the polymorphic scope of 'Selection'.
Check if class with serial name 'GridClueSelection' exists and serializer is registered in a corresponding SerializersModule.
To be registered automatically, class 'GridClueSelection' has to be '@Serializable', and the base class 'Selection' has to be sealed and '@Serializable'.
except
GridClueSelection
is Serializable, and
Selection
is sealed and Serializable.
Copy code
@Serializable
sealed class Selection { ... }

@Serializable
abstract class ClueSelection(val clueKey : String) : Selection() { ... }

@Serializable
class GridClueSelection( ... ) : ClueSelection(_clueKey) { ... }
m
I'm guessing that since
ClueSelection
is not sealed, the automatic lookup polymorphism for
GridClueSelection
is not getting created, and you will need to manually configure the serializers.
c
So the error message is wrong?
That did fix the problem.
m
No it is right.
GridClueSelection
is not in the polymorphic scope of
Selection
because it is not a subclass of
Selection
and is instead a subclass of
ClueSelection
. I don't know if making
ClueSelection
sealed will fix it or if you need to manually configure if the polymorphic scope of
Selection
.
c
The error specifically says "To be registered automatically, class 'GridClueSelection' has to be '@Serializable', and the base class 'Selection' has to be sealed and '@Serializable'"
At best that's misleading. It's necessary but not sufficient.
m
Yeah, the message message about what to check is wrong, but not what is wrong. They need to add an extra check to make, I guess.
c
I guess they weren't thinking of an inheritance hierarchy when they wrote it.
j
I guess the message should say that all super classes need to be sealed too
m
Not all super classes, just the ones in between the serialized polymorphic root and the leaf.
Object
obviously won't be sealed or
Serializable
.
👌 1
157 Views