Я использую библиотека сериализации Kotlin.
Классы выглядят следующим образом:
Код: Выделить всё
@Serializable
data class ResultOne(
val count: Int,
val result: List
)
@Serializable
data class ResultTwo(
val count: Int,
val result: List
)
@Serializable
data class TypeOne(
val str1: String,
val str2: String,
val int1: Int
)
@Serializable
data class TypeTwo(
val str1: String,
val dbl1: Double,
val int1: Int
)
Код: Выделить всё
...
import io.ktor.serialization.kotlinx.json.json
...
private val httpClient = HttpClient {
install(ContentNegotiation) {
json(Json{
isLenient = true
ignoreUnknownKeys = true
})
}
}
fun getResultTypeOne() {
val response = responseOne(listOf(1, 2)).result
}
private suspend fun responseOne(ints: List): ResultOne {
val availableShows = httpClient.get("https://my.api.com/search")
return availableShows.body()
}
fun getResultTypeTwo() {
val response = responseTwo(listOf(1, 2)).result
}
private suspend fun responseTwo(ints: List): ResultTwo {
val availableShows = httpClient.get("https://my.api.com/search")
return availableShows.body()
}
Подробнее здесь: https://stackoverflow.com/questions/772 ... rent-types
Мобильная версия