https://kotlinlang.org logo
#ktor
Title
# ktor
g

galex

03/15/2019, 7:02 AM
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

e5l

03/15/2019, 7:52 AM
Hi @galex, could you catch the exception and print cause?
g

galex

03/15/2019, 7:53 AM
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

e5l

03/15/2019, 8:08 AM
The exception reporting is fixed in master and will be available in
1.2.0
🙂
g

galex

03/15/2019, 8:11 AM
Ahhhhh sweet!!
Is there a snapshot dependency to try that out?
e

e5l

03/15/2019, 8:12 AM
1.2.0-alpha-1
but wo iOS for now.
👍 1
g

galex

03/15/2019, 8:15 AM
What can I do in the meantime in my code?
I can register a mapper right?
e

e5l

03/15/2019, 8:18 AM
Yep, but you have to pass class serializer instead of using method with generic parameter.
g

galex

03/15/2019, 8:19 AM
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
32 Views