https://kotlinlang.org logo
o

oday

07/30/2023, 3:02 PM
hi, I've implemented a very simple class with 3 fields:
Copy code
import kotlinx.serialization.Serializable

@Serializable
data class BirdImage(
    val author: String,
    val category: String,
    val path: String
)
and I have this http client using Ktor
Copy code
val httpClient = HttpClient {
    install(ContentNegotiation) {
        json()
    }
}
then i've got this simple method to just get the results from that URL
Copy code
private suspend fun getImages(): List<BirdImage> {
    val images = httpClient
        .get("<https://sebastianaigner.github.io/demo-image-api/pictures.json>")
        .body<List<BirdImage>>()
    return images
}
I am always getting back:
Expected class kotlinx.serialization.json.JsonObject as the serialized body of kotlinx.serialization.Polymorphic<List>, but had class kotlinx.serialization.json.JsonArray
if i wanna run that call
println(getImages())
kotlinx.serialization is at version
1.5.1
ktor is at
2.3.1
- tried with
2.3.2
as well, same The code is here https://github.com/Odaym/cmp-1/blob/main/shared/src/commonMain/kotlin/App.kt
SOLVED: there was a mismatch between the version of
kotlinx.serialization
plugin and the version of kotlin being used serialization was
1.8.21
and kotlin was
1.9.0
setting Kotlin back to
1.8.20
solved it that version for serialization is the latest, there's no 1.9.0 so I dont know if it supports latest kotlin
s

sandwwraith

08/03/2023, 12:15 PM
there's no 1.9.0
That is not true. Serialization plugin is released together with Kotlin, so for every Kotlin version there's a matching serialization plugin version
o

oday

08/03/2023, 12:19 PM
Aha then
Thank you for reading and correcting this!
4 Views