Hello, what is the best way to deal with this erro...
# ktor
g
Hello, what is the best way to deal with this error in Kotlin/Native:
Copy code
kotlin.NotImplementedError: An operation is not implemented: Obtaining serializer from KClass is not available on native due to the lack of reflection. Use .serializer() directly on serializable class.
After adding the
.serializer()
to
Json.stringify
I get the following error and I am not sure how to specify the serializer() for the receiving/parsing part:
Copy code
io.ktor.client.call.ReceivePipelineException: Fail to run receive pipeline
Here’s my request:
Copy code
val result: ActionResponse = <http://networkHttpClient.post|networkHttpClient.post> {
    url(address)
    body = TextContent(Json.stringify(Event.serializer(), event), contentType = ContentType.Application.Json)
}
e
Hi @galex, could you catch the exception and print cause?
g
Yup give me a sec
@e5l
Copy code
io.ktor.client.call.ReceivePipelineException: Fail to run receive pipeline
io.ktor.client.call.NoTransformationFoundException: No transformation found: class io.ktor.client.engine.ios.IosHttpResponse -> class 
com.analytics.core.network.model.ActionResponse
I see that I didn’t set up any serializer on the HttpClient(), I am trying that
👍 1
e
The exception reporting is fixed in master and will be available in
1.2.0
🙂
g
Ahhhhh sweet!!
Is there a snapshot dependency to try that out?
e
1.2.0-alpha-1
but wo iOS for now.
👍 1
g
What can I do in the meantime in my code?
I can register a mapper right?
e
Yep, but you have to pass class serializer instead of using method with generic parameter.
g
Copy code
actual val networkHttpClient: HttpClient
    get() = HttpClient {
        install(JsonFeature) {
            serializer = KotlinxSerializer(Json(encodeDefaults = false)).apply {
                setMapper(Event::class, Event.serializer())
                setMapper(ActionResponse::class, ActionResponse.serializer())
            }
        }
    }
Correct?
👍 1
Till 1.2.0 gets out where this is taken care of automatically, cool :))
@e5l it worked, you rock!
🙏 1
🙂 2