java.lang.IllegalArgumentException: Unable to create converter for com.darkknight.base.data.network.CommonResponse<java.lang.Object> for method ApiInterface.addShop
rooparsh opened this issue · 3 comments
Trying to make an API call. But whenever I add response type as Any
, I receive
java.lang.IllegalArgumentException: Unable to create converter for com.darkknight.base.data.network.CommonResponse<java.lang.Object> for method ApiInterface.addShop
error.
I am attaching the common parsing code I have been using for reference :
`suspend fun safeApiCall(apiCall: suspend () -> Response): ResultWrapper = try {
apiCall.invoke().resolveResponse()
} catch (throwable: Throwable) {
when (throwable) {
is IOException -> ResultWrapper.NetworkError(throwable.message.orEmpty())
is HttpException -> with(throwable) {
ResultWrapper.GenericError(ApiError(code(), message()))
}
else -> ResultWrapper.NetworkError(throwable.message.orEmpty())
}
}private fun Response.resolveResponse(): ResultWrapper =
if (this.isSuccessful) {
this.body()?.let {
ResultWrapper.Success(it)
} ?: kotlin.run {
ResultWrapper.GenericError(this.errorBody().toApiError())
}
} else {
ResultWrapper.GenericError(this.errorBody().toApiError())
}@OptIn(UnstableDefault::class)
private fun ResponseBody?.toApiError(): ApiError = Json(
JsonConfiguration(
ignoreUnknownKeys = true,
isLenient = true
)
).parse(
ApiError.serializer(),
this?.charStream()?.readText().orEmpty()
)`
as well as the Api signature @POST("api/v1/shop") @Headers("Content-type: application/json") suspend fun addShop( @HeaderMap headerMap: HashMap<String, String>, @Body map: HashMap<String, String> ): Response<CommonResponse<Any>>
My Current Versions are as follows :
retrofit2_version = '2.8.1' coroutines_android_version = '1.3.0' coroutines_core_version = '1.3.3' coroutines_ext_adapter_version = '0.9.2'
implementation "com.squareup.retrofit2:retrofit:$retrofit2_version" implementation "com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:0.5.0"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_android_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_core_version" implementation "com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:$coroutines_ext_adapter_version"
Any workaround??
and solution waS?