How to handle requesting unsafe Jsons with ktor

Hi, I defined some data classes but the problem is that when requesting a json like this:

val response: List<MyDataClass> = client.get(myUrl).body()

it often fails because some of the objects sometimes have missing keys. In that case i’d like that key to just not be in my data class. I could go on and do

“if key is there then include into the data class obj”

for every key but that is cumbersome. That is ussualy how i did it in python before i add it to a dictionary. For kotlin, i could not find anything except giving every field in the data class a default null value and then just manually remove each field that has value null. But is there a better way ?

submitted by /u/Ozay0900
[link] [comments]