Tony
04/15/2020, 3:22 PMCody Engel
04/15/2020, 3:27 PMCody Engel
04/15/2020, 3:28 PMTony
04/15/2020, 3:32 PMCody Engel
04/15/2020, 5:22 PMtext
to Any
? It's not a great solution, but could be the quickest/easiest.
The next option would be looking at custom serializers (linked in this message). The way I'd look to build it out is you'd have a sealed class with data classes inside of it, something like this:
sealed class ApiResponse<T> {
abstract text: T
data class AsString<String>(override text: String): ApiResponse()
data class AsList<List<Any>>(override text: List<Any>>): ApiResponse()
}
The above example was just typed in Slack so probably not perfect but that's the general idea. Then your customer serializer would handle the different scenarios. If you have control over the API then I'd recommend asking the engineers to update it to just return a List<String>
since that sounds like what it should be.
https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/custom_serializers.mdTony
04/15/2020, 5:24 PMCody Engel
04/15/2020, 5:29 PMdecodeString()
so if there is a decodeList
and both of them throw an exception, worst case is you can check for those exceptions as a crude if/elseCody Engel
04/15/2020, 5:30 PM