I started converting a project from <#CB2MT3VFC|ja...
# ktor
s
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
what's the use case for having different mappers based on path params?
s
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
it's sounds like a bit of an edge case, yeah
could you show how ktor handles this?
s
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
okay, thanks