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

MarkRS

06/13/2022, 4:48 PM
The migration docs for 2.x say that I can receive an arbitrary object with (something like)
Copy code
val customer: Customer = client.get("<http://localhost:8080/customer/3>").body()
and I'm assuming this works for post too, but whatever I do I can't find a way to do this in commonMain of a KMM app. Does this need to be platform specific? I've got the content negotiation plugin loaded into the HttpClient, and imported into the class making the call, it just complains that "body" is an unresolved reference. Can someone point me in the right direction, please.
r

Renaud

06/13/2022, 4:49 PM
Where are you providing ?
Copy code
api("io.ktor:ktor-serialization-kotlinx-json:2.0.2")
m

MarkRS

06/13/2022, 4:54 PM
In the commonMain sourceset of the shared module. In fact I had it as "implementation" rather than api, but, having changed it, I've got the same error 😕
Fixed. The "trick" was in adding extra imports, none of which were particularly obvious, and not added automatically due to the "IDE not recognising external imports" issue in AS (is there a fix for this yet? I've seen lots of talk here but not a fix). I used the imports from the example https://github.com/ktorio/ktor-documentation/blob/main/codeSnippets/snippets/clien[…]ate-non-2xx-response/src/main/kotlin/com/example/Application.kt (without the cio one, of course).
2 Views