Hello I'm moving to the new version of retrofit an...
# coroutines
j
Hello I'm moving to the new version of retrofit and I was using a convertor that was creating a
ResultWrapperT
from
CallT
but now reading this answer [1] from stackoverflow then I realized that if I'm using
suspended fun
I do not have to add the
CallT
so, how do I do the change now? I was using this method :
Copy code
fun <reified T:Any> execute(function: () -> Call<T>): ResultWrapperT =
        try {
            when (T::class) {
                Unit::class -> function().execute().let {
                    ResultWrapper.Success(Unit as T)
                }
                else -> function().execute().body()?.let {
                    ResultWrapper.Success(it)
                } ?: ResultWrapper.Error(Exception("no body there"))
            }
        } catch (e: Exception) {
            ResultWrapper.Exception(e)
        }
Any idea? The problem now is that as it's not a
CallT
I do not have the
execute()
method... [1] : https://stackoverflow.com/a/57810074/4329781
k
Remove the
execute()
?
j
But how do I check if it contains body or if it's success then?
I was using execute to check the body or if it was a Unit
k
I'm guessing
function
now returns
T?
. It might also be useful to constrain T to be non nullable:
<reified T:Any>
wait something looks wrong with your function signature
shouldn't your function be inline if it's reified or am I missing something?
j
sorry mistyped yep
Let me explain the problem, the problem is : I was trying to use retrofit as :
@GET("/") suspended fun pew(something) : ResultWrapper<POJO>
but was not working, then the problem is that I can not do that... So I have to do like a "migration" or whatever you want to call from
@GET("/") suspended fun pew(something) : POJO
and then change it to
ResultWrapper<POJO>
is it possible?
You got me?
@Kroppeb any idea??
k
No not really