Alexander Black
11/30/2021, 7:08 PMjava.lang.ClassCastException: java.util.ArrayList cannot be cast to kotlin.Resul
? Should I report this as a bug? I’m able to use the Kotlin result library without issue for many result types, but weirdly not with lists. I’m simply trying to return a result from an API request as a list, but having trouble doing so.
My method looks like this
suspend inline fun <reified T> get(route: String,
block: RequestBuilder.() -> Unit = {}): Result<T> {
if (networkReachability.isNetworkAvailable) {
return try {
val options = RequestBuilder().apply(block)
val response = client.get<T>("$baseUrl$route") {
headers {
sessionId.value?.also {
append("API-KEY", it)
}
}
if (options.requestPerms.isNotEmpty()) {
options.requestPerms.forEach {
// this sets the URL query parameters
this.parameter(it.first, it.second)
}
}
}
Result.success(response)
} catch (e: Exception) {
return handleError(e)
}
} else {
return Result.failure(NetworkNotReachable)
}
}
my T
type in this case is a Listephemient
11/30/2021, 8:58 PMAlexander Black
12/01/2021, 4:48 AMephemient
12/01/2021, 4:53 AM