Hey :wave: I'm trying to use <ktor in Kotlin noteb...
# ktor
l
Hey 👋 I'm trying to use ktor in Kotlin notebook (
%use ktor-client
). I need to configure a DataConversion to convert String to kotlin LocalDateTime object. However, the conversion doesn't seem to be triggered 🧵
Here is the code
Copy code
http.config {
    install(DataConversion) {
        convert<LocalDateTime> {
            decode { values ->
                println("Decoding")
                ...
            }

            encode { dates ->
                println("Encoding")
            }
        }
    }
}.get($url) {
    ...
}.body<Response>()
I consistently get
Illegal input: java.time.format.DateTimeParseException: Text '20240808T164502+0100' could not be parsed at index 0
None of the
println
is executed. Do I miss anything?
c
I guess you need
ContentNegotiation
instead of
DataConversion
https://ktor.io/docs/client-serialization.html#serialization_dependency
a
As far as I can see, the
DataConversion
plugin for the client side has an empty implementation of the
install
method, so it does nothing. You can use this plugin for the server, though.
l
@Aleksei Tirman [JB] the thing is there's no plugin for the server in kotlin notebook.
ktor-client
is the only lib available @Chrimaeon I can't really see how to do make it with
ContentNegociation
anyway, I had to work around by using an intermediate object (with all
String
fields) and manually do the conversion