Created
June 18, 2020 16:14
-
-
Save lukaszkalnik/7d39c4020e9e0e11949015991ea5d748 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class EitherCallAdapterFactory : CallAdapter.Factory() { | |
override fun get( | |
returnType: Type, | |
annotations: Array<Annotation>, | |
retrofit: Retrofit | |
): CallAdapter<*, *>? { | |
if (getRawType(returnType) != Call::class.java) return null | |
check(returnType is ParameterizedType) { "Return type must be a parameterized type." } | |
val responseType = getParameterUpperBound(0, returnType) | |
if (getRawType(responseType) != Either::class.java) return null | |
check(responseType is ParameterizedType) { "Response type must be a parameterized type." } | |
val leftType = getParameterUpperBound(0, responseType) | |
if (getRawType(leftType) != ApiError::class.java) return null | |
val rightType = getParameterUpperBound(1, responseType) | |
return EitherCallAdapter<Any>(rightType) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment