Is there a way to, using the ktor client, handle a...
# ktor
e
Is there a way to, using the ktor client, handle a response that can be of different type when performing a POST request? I was thinking of using
sealed class
for this but I’m falling short when it comes to supporting the de-serialization of the response. So something like
sealed class ApiResponse
<http://client.post|client.post><ApiResponse> {  }
@Serializable data class ErrorResponse(...) : ApiResponse()
@Serializable data class SuccessResponse(..) : ApiResponse()
r
Do you use
KotlinxSerializer
? Is it JVM or some other target?
e
Yes, I’m using `KotlinSerializer`and targeting iOS and Android in MPP
r
iOS can't acquire serializers via reflection, so you'll have to register all your serializers manually. Also, as far as I'm aware, polymorphic serializer for multi-platform is WIP right now.
https://github.com/Kotlin/kotlinx.serialization/pull/394 Here's PR which you can track for progress. Unfortunately I'm unable to find relevant issue.
e
Excellent, thank you for pointing me towards this 👍
r
Glad I could help!