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

sbyrne

02/28/2019, 2:40 PM
I started converting a project from #javalin to ktor, just to learn about it. Some of the things I was worried about because I had to do hacky things in Javalin were very easy in ktor due to the well thought out Features and and pipeline. (e.g.: different Jackson ObjectMapper based on path parameters)
🎉 2
t

tipsy

02/28/2019, 3:52 PM
what's the use case for having different mappers based on path params?
s

sbyrne

02/28/2019, 4:04 PM
It is a peculiarity of my application, not something I think the framework should handle natively.
I have a route
{name}/{subpath...}
(or
{name}/*
in javalin) under which the parsing of the subpath (in both the URL and inside JSON) have different rules depending on
{name}
.
It was probably a poor design decision on my part.
1
t

tipsy

02/28/2019, 5:00 PM
it's sounds like a bit of an edge case, yeah
could you show how ktor handles this?
s

sbyrne

02/28/2019, 5:55 PM
I have an interceptor in
route("{name}")
that puts an object that contains the `name`'s configuration and
ObjectMapper
into the context, and wrote a custom
ContentConverter
that gets it from the context and uses it.
In Javalin I do a very similar thing - I have a
before
in
path(":name")
that puts the ObjectMapper in the context. To use it I wrote an extension function
Context.writeWithMyCustomMapper(obj:Any)
that gets the ObjectMapper and writes to
objectWriter
.
t

tipsy

02/28/2019, 7:29 PM
okay, thanks