Using kotlinx.serialization…
val card: Card? = getCard(...)
val json = if (card == null) "null"
else Json.stringify(Card.serializer(), card)
That’s fairly clear, but I’m just wondering if I’m missing some standard way to handle T?
when you have a KSerializer<T>
I guess “null” is isn’t technically JSON format, but if I have a HTTP response that sends a Card?
I’d rather do it this way than create a data class CardResponse(card: Card?)
just for this.