Ktor: Kotlin 1.3.70

Created on 4 Mar 2020  路  13Comments  路  Source: ktorio/ktor

Need to update kotlin dependencies up to 1.3.70
https://blog.jetbrains.com/kotlin/2020/03/kotlin-1-3-70-released/

feature

Most helpful comment

We are waiting for kotlinx.coroutines build with 1.3.70 first

kotlinx.coroutines release new version support kotlin 1.3.70
https://github.com/Kotlin/kotlinx.coroutines/releases/tag/1.3.4

All 13 comments

Apart from the usual iOS / macOS Framework woes, Ktor still works like a charm. However, if _KotlinX.Serialization_ is used, it needs to be updated to version 0.20.0 in conjunction with the Kotlin update

We are waiting for kotlinx.coroutines build with 1.3.70 first

Deps are
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:0.20.0"
using kotlin 1.3.61/1.3.70, tried them both, along with ktor version 1.3.1. I get the following crash when trying to use following mock http client for testing.

HttpClient(MockEngine) {

    install(JsonFeature) {
        serializer = KotlinxSerializer().apply {
            setMapper(TestModel::class,TestModel.serializer())
        }
    }

The following is the class I use for the serializable model

import kotlinx.serialization.Serializable

@Serializable
data class TestModel(val someString: String) {
}

What is the status on this, I know above someone mentioned coroutines needed to be updated, is that holding this up? For now I need to wait or manually serialize everything outside the ktor HttpClient to use the kotlinx.serialization runtime library.

java.lang.NoSuchFieldError: Companion
at io.ktor.client.features.json.serializer.KotlinxSerializer.(KotlinxSerializer.kt:22)
at test.actual.SecondMockHttpClientKt$secondMockHttpClient$1$1.invoke(SecondMockHttpClient.kt:17)
at test.actual.SecondMockHttpClientKt$secondMockHttpClient$1$1.invoke(SecondMockHttpClient.kt)
at io.ktor.client.HttpClientConfig$install$2.invoke(HttpClientConfig.kt:62)
at io.ktor.client.HttpClientConfig$install$2.invoke(HttpClientConfig.kt:16)
at io.ktor.client.features.json.JsonFeature$Feature.prepare(JsonFeature.kt:82)
at io.ktor.client.features.json.JsonFeature$Feature.prepare(JsonFeature.kt:78)
at io.ktor.client.HttpClientConfig$install$3.invoke(HttpClientConfig.kt:70)
at io.ktor.client.HttpClientConfig$install$3.invoke(HttpClientConfig.kt:16)
at io.ktor.client.HttpClientConfig.install(HttpClientConfig.kt:90)
at io.ktor.client.HttpClient.(HttpClient.kt:146)
at io.ktor.client.HttpClientKt.HttpClient(HttpClient.kt:40)
at test.actual.SecondMockHttpClientKt.(SecondMockHttpClient.kt:14)
at com.ntent.artemis.KtorMockApiTest$simpleTest$1.invokeSuspend(KtorMockApiTest.kt:50)
at com.ntent.artemis.KtorMockApiTest$simpleTest$1.invoke(KtorMockApiTest.kt)
at test.actual.RunTestKt$runTest$1.invokeSuspend(RunTest.kt:6)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:271)
at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:79)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:54)
at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:36)
at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
at test.actual.RunTestKt.runTest(RunTest.kt:6)
at com.ntent.artemis.KtorMockApiTest.simpleTest(KtorMockApiTest.kt:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:110)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:412)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
at java.lang.Thread.run(Thread.java:748)

Follow up question, for the setMapper(TestModel::class,TestModel.serializer()) that is now deprecated in order to use typeOf(). How will one implement that using

install(JsonFeature) {
        serializer = KotlinxSerializer().apply {
            setMapper(TestModel::class,TestModel.serializer())
        }
    }

Thanks!

kotlinx.serialization 0.20.0 and kotlin 1.3.70 are not compatible with 0.14.0 and ktor 1.3.1. Absolutely no way.

You simply don't need to invoke setMapper at all: just set serializer to KotlinxSerializer and that's all.

So when I just try that

HttpClient(MockEngine) {
    install(JsonFeature) {
        serializer = KotlinxSerializer()
    }
}

using My TestModel class that is marked @Serializable I get the following error:

io.ktor.client.call.NoTransformationFoundException: No transformation found: class io.ktor.utils.io.ByteBufferChannel -> class com.ntent.artemis.TestModel
with response from http://test.api/stuff:
status: 200 OK
response headers:
at io.ktor.client.call.HttpClientCall.receive(HttpClientCall.kt:79)

kotlinx.serialization 0.20.0 and kotlin 1.3.70 are not compatible with 0.14.0 and ktor 1.3.1. Absolutely no way.

Alright well thanks for that, I missed it yesterday. To me that is very confusing because ktor does uses the kotlinx.serialization plugin for marking data classes serializable. But then you can't use the runtime dependency of kotlinx.serialization.

After many attempts I finally get the runtime of kotlinxserial and ktor are not compatible. I was only interested in the latest 0.20.0 version of kotlinx.serialization runtime also, for making custom serializers.

@cy6erGn0m any updates about release date?
are there any snapshot or EAP repositories with 1.3.70? I really want to prepare my repos with 1.3.70 and ktor

We are waiting for kotlinx.coroutines build with 1.3.70 first

kotlinx.coroutines release new version support kotlin 1.3.70
https://github.com/Kotlin/kotlinx.coroutines/releases/tag/1.3.4

Any updates??

As mentioned, a few days ago they released kotlinx.coroutines for 1.3.70. When are we going to see this for ktor?

Ok. 1.3.2 release. Thank u.

Was this page helpful?
0 / 5 - 0 ratings