https://kotlinlang.org logo
#serialization
Title
# serialization
a

arekolek

02/28/2024, 11:42 AM
I want to detect situation in which server returned a 200 OK response, but there was a problem on client side with reading the response I hoped to use
kotlinx.serialization.json.internal.JsonDecodingException
but it is an internal API so I have to use reflection is there any better way to do this?
s

spand

02/28/2024, 12:03 PM
Would it work if you catch the super class
SerializationException
?
a

arekolek

02/28/2024, 12:42 PM
that's probably actually better 🤔 thanks for pointing it out https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization/-serialization-exception/
For general "catch-all" patterns around deserialization of potentially untrusted/invalid/corrupted data it is recommended to catch
IllegalArgumentException
type
they even say I might want to go one step further