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

hdarritchon

04/07/2020, 11:54 PM
Hi, I’m trying to handle a response from a ReST API with Ktor Client. This API has several types of response depending if it is a success or an error. I’m trying to handle this with a Sealed class. But I fail to do it. I tried using Gson/Jackson and Json. I saw the polymorphic (https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/polymorphism.md) documentation but I have an issue because one of the attributes of the API is ‘type’ and it’s the classDiscriminator by default and I tried to change it with JsonConfiguration but with no success. I am quite stuck. Any help doing this ? Do you a tutorial, some information ? Thanks. If it is needed I can give access to the code in github (https://github.com/herveDarritchon/icndb). Everything is in the Application.kt file (https://raw.githubusercontent.com/herveDarritchon/icndb/master/src/Application.kt)
j

Johannes Zick

04/08/2020, 8:47 AM
I have not tried this before. But comparing those links, have you tried specifying the type names explicitly? By default it should use fully qualified class names, but maybe that still helps.
4 Views