sushma nayak
03/22/2021, 9:44 PMoverride suspend fun <T : Any> getJsonFromRouter(router: APIRouter, success: Success<T>, failure: Failure) {
try {
val json = httpClient.get<String>(requestFromRouter(router))
Json.decodeFromString(T.serializer(), json)
.entries
.also(success)
} catch (ex: Exception) {
Failure(error = ex)
}
}
I’m getting error on T.serializer()
. Error = “Not enough information to infer type variable T”. On iOS we have Decodable which allows these kind of generic implementation.
Was wondering if this is allowed on kotlin or this can’t be achieved and an actual type in place if generic T is required?rnett
03/22/2021, 10:47 PMgetJsonFromRouter
inline, you can use reified
on T
. Otherwise I'd probably take the serializer as a parameter or take the KType
(but you lose type safety with KType
).sushma nayak
03/23/2021, 5:35 AMreified
on T
because its defined in an interface.