I made this serializer for my json structure ```companion object Serializer : JsonContentPolymorphic...
z
I made this serializer for my json structure
Copy code
companion object Serializer : JsonContentPolymorphicSerializer<Renderer>(Renderer::class) {
    override fun selectDeserializer(element: JsonElement) = when {
        "slimVideoMetadataSectionRenderer" in element.jsonObject -> SlimVideoMetadataSectionRenderer.serializer()
        "itemSectionRenderer" in element.jsonObject -> RelatedItemsRenderer.serializer()
        "shelfRenderer" in element.jsonObject -> ShelfRenderer.serializer()
        else -> throw NoWhenBranchMatchedException()
    }
}
though how would I make it serialize using the object inside of the key?
z
That's not as nice as an approach and I think that would just do the same thing as what I found
e
it does not do the same thing. the
JsonContentPolymorphicSerializer
approach will attempt to deserialize
{"slimVideoMetadataSectionRenderer": "**", "*a*": "**", "b": "*"}
for a
data class SlimVideoMetadataSectionRenderer(val a: String, val b: String)
and will serialize to a
{"a": "*", "b": "*"}