oday
07/30/2023, 3:02 PMimport kotlinx.serialization.Serializable
@Serializable
data class BirdImage(
val author: String,
val category: String,
val path: String
)
and I have this http client using Ktor
val httpClient = HttpClient {
install(ContentNegotiation) {
json()
}
}
then i've got this simple method to just get the results from that URL
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.ktkotlinx.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 kotlinsandwwraith
08/03/2023, 12:15 PMthere's no 1.9.0That is not true. Serialization plugin is released together with Kotlin, so for every Kotlin version there's a matching serialization plugin version
oday
08/03/2023, 12:19 PM