Hi! I have been trying to create a call adapter in...
# announcements
h
Hi! I have been trying to create a call adapter in Retrofit for suspending functions that return a sealed class type. Something like this:
Copy code
@GET("/")
suspend fun getSomething(): MySealedClass<SuccessType, ErrorType>
On a Reddit discussion thread, Jake left some instructions on how this could be done: https://www.reddit.com/r/androiddev/comments/c6m3yv/network_request_wrapper_extension_for_retrofit_26 Here's the relevant part:
suspend fun whatever(): Whatever
will ask Retrofit for a CallAdapter to handle
Call<Whatever>
. Knowing this, you can register a
CallAdapter.Factory
which looks for
Call<YourSealedClass<BodyType>>
, delegates to the built-in factory for
Call<BodyType>
, and then wraps the value in
YourSealedClass
. This will allow
suspend fun whatever(): YourSealedClass<Whatever>
to work–no extension needed.
I am unable to figure out how to do the delegation part. I have a call of the type
Call<MySealedClass<SuccessType, E>>
, and need to find a delegate which can adapt
Call<SuccessType>
. More specifically, I can not figure out how to create a Parameterized Type Token for
Call<SuccessType>
so that I can pass it to retrofit to find the delegated adapter for me. I would really appreciate some help with this.