Hey I was wondering how I would handle this intera...
# serialization
t
Hey I was wondering how I would handle this interaction. I have an API written in TypeScript that returns a
data
field where in Kotlin I serialize into this basic object
Copy code
@Serializable
data class PayloadData<T>(
    val error: Boolean,
    val data: T? = null
)
However, sometimes when no data needs to be sent back the data field sent back is undefined, and I try to set the type of PayloadData to Void and kotlinx serialization fails, was wondering if there was a way to handle this case?
e
kotlinx.serialization 1.5.0 includes a "serializer" for
Nothing
, so
PayloadData<Nothing>(data = null)
should work
t
Oh really? I thought Nothing represented no operation was done and would just throw an error, I’ll try it out when I can though
e
there are no values of type
Nothing
, but there is
null: Nothing?
t
ah gotcha just use nothing as a sort of proxy to serialize a null