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

Patrick

09/28/2020, 12:31 PM
Is it possible to use kotlinx.serialization with the newest version of ktor server? It seems like the documentation is outdated, since I can't find the serialization() function in kotlinx.serialization. https://ktor.io/docs/serialization-converter.html#configuration
j

Joost Klitsie

09/28/2020, 1:09 PM
Copy code
install(ContentNegotiation) {
        json(Json {
            ignoreUnknownKeys = true
            isLenient = true
            prettyPrint = true
        })
    }
This is what I use with ktor 1.4.0
the Json is from the serialization
p

Patrick

09/28/2020, 1:11 PM
It says: required: JsonObjectBuilder.() -> Unit, Found: Json
I am using ktor 1.4.0 and kotlinx.serialization version 1.0.0-RC2
j

Joost Klitsie

09/28/2020, 1:19 PM
Maybe try serialization 1.0.0-RC
OR ktor 1.4.10 with serialization 1.0.0-RC2
p

Patrick

09/28/2020, 1:19 PM
is that the version you are using?
j

Joost Klitsie

09/28/2020, 1:19 PM
yes
p

Patrick

09/28/2020, 1:19 PM
ok i'll try 1.4.10
j

Joost Klitsie

09/28/2020, 1:20 PM
I use 1.4.0 with 1.0.0-RC
I think for 1.4.10 you can use 1.0.0-RC2
but you also have to add "kotlinx-serialization-json"
org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.0-RC2
p

Patrick

09/28/2020, 1:37 PM
I don't think version 1.4.10 exists
j

Joost Klitsie

09/28/2020, 1:40 PM
sorry 1.4.1
p

Patrick

09/28/2020, 1:40 PM
Ah I see
I think it works with 1.4.1
j

Joost Klitsie

09/28/2020, 1:40 PM
which supports kotlin 1.4.10 😄
p

Patrick

09/28/2020, 1:50 PM
Hmm I am still getting the same error
j

Joost Klitsie

09/28/2020, 1:52 PM
which ktor dependencies do you have?
p

Patrick

09/28/2020, 1:53 PM
Copy code
val ktorVersion = "1.4.1"

implementation("io.ktor:ktor-server-core:$ktorVersion")
    implementation("io.ktor:ktor-server-netty:$ktorVersion")
    implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.0-RC2")
j

Joost Klitsie

09/28/2020, 1:54 PM
do you also include
io.ktor:ktor-serialization:1.4.1
p

Patrick

09/28/2020, 1:57 PM
I didn't, it looks better now
But now I am getting this error: Exception in thread "Thread-0" java.lang.NoSuchMethodError: 'kotlinx.serialization.json.Json kotlinx.serialization.json.JsonKt.Json$default(kotlinx.serialization.json.Json, kotlin.jvm.functions.Function1, int, java.lang.Object)'
At least it compiles now
3 Views