HyeonBae Ji
05/11/2024, 9:13 AMval rawText = rawResponse.text
._filterKeys_ *{ it* != "text" *}*
._mapValues_ *{*
_defaultJson_._decodeFromJsonElement_<TextResponse>(*it*.value)
}
Websocket API Case :
I’m taking data as a Text type, filtering it and convert it back to the data class type with decodeFromString.
Like this
val json = *it*._readText_()
if (json._contains_("text")) {
_defaultJson_.decodeFromString<TextResponse>(json)
} else null
I was thinking of creating multiple data classes for a single call, but I don't know how to do this either. If you have a way to do this, please let me know the keywords!Samuel G
05/11/2024, 1:04 PMval request = kotlin.runCatching { call.receiveNullable<YourDataClass>() }.getOrNull() ?: kotlin.run {
call.respond(HttpStatusCode.BadRequest)
return@post
}
This will automatically convert the Json object to your data class specified in "call.receiveNullable<*YourDataClass*>()" and if the Json object is empty or does not conform to the data class, it will reject it, so keep that in mind.
You can access it by using the "request" variable.
I don't know much about Websockets or multible data classes per call so I cant help you there.