bump on my question from above... is there a way in kotlin to serialize a json field that can essentially be a union type (either a boolean, or a data class)
k
kevin.cianfarini
04/10/2023, 1:08 PM
Defined a sealed interface/class that wraps the type and serialize that
the quick-and-easy approach is to manually convert the property to or from a JsonElement
Copy code
@Serializable
data class MyData(
val someElement: JsonElement,
) {
val someElementAsBoolean: Boolean? = if (JsonElement is JsonPrimitive) ... else null
}