Hi all, I'm using Ktor with Json content serialize...
# ktor
m
Hi all, I'm using Ktor with Json content serializer. Everything is perfect but now I want to be able to return Eithers form Arrow. The serializers are given by Arrow team but I don't know how to configure them (the either is directly the return of the service). Anyone knows how to add a custom serializer for a return type? Thanks,
a
Can you please illustrate your question with some code?
m
I've simplified it to:
Copy code
get<Either<String, String>>{
    val result : Either<String, String> = "a".right()
    call.respond(result)
}
p
Generally you wouldn't want to serialize/respond with the Left of an either the same way you would the Right (as you'd likely want a different status code or body for different domain errors)
An example way of handling an
Either
from a route would be to have an extension on
PipelineContext<Unit, ApplicationCall>
that would handle calling the appropriate
call.respond
based on if the either is Left or Right
m
I know is kind of "dirty". The thing is that I'm building the client and server. If I return and recieve an Either I don't need to do the transform and untransform.