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

Pedro Alberto

01/31/2023, 12:28 AM
Copy code
io.ktor.client.call.NoTransformationFoundException: No transformation found: class io.ktor.utils.io.ByteBufferChannel (Kotlin reflection is not available) -> class com..ApiResponse (Kotlin reflection is not available)
am trying to parse an array of ints but seems impossible
Copy code
{
  "numbers": [
    4, 150,...
  ]
}
obj am using is
Copy code
@Serializable
class ApiResponse(val numbers: Array<Int>)
calling it like this
Copy code
val response: ApiResponse = httpClient.get(url).body()
a

Aleksei Tirman [JB]

01/31/2023, 8:56 AM
Can you tell me if you target the Kotlin/Native?
p

Pedro Alberto

01/31/2023, 10:46 AM
am using kotlin multiplatform project am trying to have the same parser for both platforms
any ideas @Aleksei Tirman [JB]?
a

Aleksei Tirman [JB]

01/31/2023, 3:59 PM
Unfortunately, I cannot reproduce your problem with the following code: Client:
Copy code
val client = HttpClient(Darwin) {
    install(ContentNegotiation) {
        json()
    }
}
val r = client.get("<http://localhost:4444/>").body<ApiResponse>()
println(r.numbers.first())
Server:
Copy code
embeddedServer(Netty, port = 4444) {
    routing {
        get("/") {
            call.respondText(contentType = ContentType.Application.Json) { """
                {
                  "numbers": [
                    4, 150, 6, 8
                  ]
                }
            """.trimIndent() }
        }
    }
}.start(wait = true)
p

Pedro Alberto

02/01/2023, 9:23 AM
@Aleksei Tirman [JB] could it be is the client this is android am using
a

Aleksei Tirman [JB]

02/07/2023, 8:01 PM
So you’re running your code on an Android emulator or Android physical device?
6 Views