I’m reading official documentation on GitHub, and it looks like I need to add `SerialName` to all im...
e
I’m reading official documentation on GitHub, and it looks like I need to add
SerialName
to all implementations to serialise the sealed interface. However, when I try to test it, I see that serialiset is not found for the discriminator. Does it mean I have to define all subclasses when defining the serializable module?
d
You don't need to add it but it's good practice to do so. If the discriminator is missing then you're using the wrong serializer.
e
There is class with this discriminator that serialiser looks like can not find
d
Do you have a code snippet?
e
Copy code
@Serializable
internal sealed class SocketMessage : BaseSocketMessage {...

@Serializable
@SerialName("typing")
internal data class TypingSocketMessage(...)
Error:
Copy code
Polymorphic serializer was not found for class discriminator 'typing'
d
Shouldn't
TypingSocketMessage
extend
SocketMessage
?
e
It does
d
How are you serializing?
e
Copy code
private fun parseMessage(json: String): SocketMessage {
    return json.decodeFromString(json)
d
Nothing seems wrong from the snippets and messages. Create an issue with a reproducer.
e
Super thank you for the validation
p
Can you try with an explicit SocketMessage.serializer() It might be related to the serializer module
e
I will try it tomorrow
@Dominaezzz You were right the class was extending the different interface - we have around 35 these messages and this one only one was different
d
Ah nice! Glad you found the issue.