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

Enrico Saggiorato

03/05/2022, 10:52 AM
Hey, I'm having some trouble with kotlinx.serialization, I defined a class to deserialize a request, annotated it with Serializable and then from inside a route I'm calling call.receiveOrNull<MyRequest>() But insted of null I'm getting an exception when the request is bad formed. Is this the expected behavior? And if yes what's the point of receiveOrNull?
I was also trying to handle exceptions, but it seems like kotlinx.serialization exceptions are internal, so I can only catch Exception? Is there some way to differentiate between the errors?
a

Aleksei Tirman [JB]

03/05/2022, 5:54 PM
Here you can find an explanation about the
receiveOrNull
behavior logic. There is the SerializationException that is the only public exception class. Unfortunately, there is no way to differentiate kotlinx.serialization library errors.
e

Enrico Saggiorato

03/05/2022, 7:25 PM
hey, thanks for the answer! I don't know enough about networking to think about an example for negotiation failing... anyway, am I doing it right? Do I have to catch exceptions in order to handle the bad requests?
b

bartosz.malkowski

05/26/2022, 5:23 PM
który client json array
3 Views