Hi, any known workarounds for avoiding the type in...
# serialization
g
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
If you don't need the discriminator (i.e. polymorphism) then serialise the subclass instead of the base class.
g
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
lol, im dumb. Now i got what you meant 🙃
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
👍🏼 1