Hi, any known workarounds for avoiding the type in json serialization?. For deserializing i can provide a selectDeserializer. Im found this https://github.com/Kotlin/kotlinx.serialization/issues/1247 but i think it does not mention any workaround for erasing the type in serialization. My use case is pretty simple i think, i just have a sealed interface with an implementation
d
Dominaezzz
01/27/2022, 4:37 PM
If you don't need the discriminator (i.e. polymorphism) then serialise the subclass instead of the base class.
g
George
01/27/2022, 4:39 PM
Do you have any examples so i can see? By default my base class (in my case the interface does not need the @serializable), i only mark serializable the implementation
George
01/28/2022, 10:33 AM
lol, im dumb. Now i got what you meant 🙃
George
01/28/2022, 10:34 AM
Fyi, this is the outcome
Copy code
public fun SharedPayload.encodeToJson(): JsonElement = (this as SharedSharedPayloadFromBuilder).encodeToJson()
internal fun SharedSharedPayloadFromBuilder.encodeToJson(): JsonElement = Json.encodeToJsonElement(this)
I can say it's not bad, Thanks for the pointer dominic