https://kotlinlang.org logo
Title
k

Kris Wong

01/14/2020, 9:57 PM
let's say I am using HttpClient w/ serialization, and I want to handle the case of invalid JSON by getting the response text. is that possible, or do I need to receive the response as text and deserialize manually?
d

Dico

01/14/2020, 10:20 PM
Just catch
JsonProcessingException
assuming you're using jackson
k

Kris Wong

01/14/2020, 10:21 PM
i am using kotlinx.serialization
d

Dico

01/14/2020, 10:30 PM
then catch the corresponding error for json deserialization - they are not caught by ktor when calling
receive<T>()
Well, they are caught by some early phase and printed to the console
k

Kris Wong

01/14/2020, 10:32 PM
yes, that's quite easy, but how do I get the response text?
d

Dico

01/14/2020, 10:33 PM
with jackson the error has the full response available I think. Perhaps kotlinx.serialization has some info about it as well? What do you want to do with it?
k

Kris Wong

01/14/2020, 10:34 PM
the exception has a character position and what the specific error was, but it does not include the json text
I want to rethrow including the json text