Hello I'm using Ktor Client and I faced an issue that I don't know how to solve although I think I have some ideas on how to solve it
Disclaimer: I don't know if I should post it here or
#serialization 😅
There's an API that for the same parameter can return a
String
or a
List<String>
, if I get the response and use
response.body<MyClass>()
For instance this is
MyClass
@Serializable
data class MyClass(
val parameter: String // Could also be List<String>
)
Of course this fails to serialize because there's an illegal input, expect a specific type not both.
This crashes when finds that there's some parameter in the json that is a
List<String>
I was thinking of ways to solve it, and the first thought was setting
Any
but, of course, breaks the serialisation laws.
Then I thought that maybe I can do some custom deserialization but I don't wanna spend too much time shooting my shot in the dark.
Do you know if that's the way or is there any other better approach?