java.lang.RuntimeException: Failed to invoke private com.skydoves.sandwich.ApiResponse() with no args
JosephSanjaya opened this issue · comments
Please complete the following information:
- Library Version 1.2.1
- Affected Device(s) Pixel 4
Describe the Bug:
response that used Sandwich always failed, with exception like above
Expected Behavior:
Response should be success because implementation without Sandwich had no problem
Implementation:
@GET("api/v3/rekening/detail")
suspend fun getRekeningDetail(
@Header("Authorization") auth: String,
@Query("id") id: String,
@Query("type") type: String
): ApiResponse<ResponseResult<Rekening>>
data class ResponseResult<T>(
@field:SerializedName("data")
val data: T? = null,
@field:SerializedName("message")
val message: String? = null,
@field:SerializedName("status")
val status: Int? = null
)
fun getRekeningById(rekeningId: String, rekeningType: RekeningType) = flow {
emit(State.Single.Loading())
var rekeningData: Rekening? = null
if (NetworkUtils.isConnected()) {
val response =
service.getRekeningDetail(
mSecuredPreferences.accessToken,
rekeningId,
rekeningType.value
)
response.suspendOnSuccess {
dao.insertSyncData(listOf(data.data))
rekeningData = dao.getRekeningById(rekeningId)
}.suspendOnError {
rekeningData = dao.getRekeningById(rekeningId)
}.suspendOnException {
rekeningData = dao.getRekeningById(rekeningId)
}
} else {
rekeningData = dao.getRekeningById(rekeningId)
}
emit(State.Single.Success(rekeningData))
}.flowOn(Dispatchers.IO)
Hi, Could you share your Retrofit Builder?
If you don't use the CoroutinesResponseCallAdapterFactory
or use it with another factory, RuntimeException
will happen.
this is my retrofit builder
val retrofit: Retrofit = Retrofit.Builder()
.baseUrl(Secured.getBaseUrlApi(isBareksa))
.client(okHttpClient)
.addCallAdapterFactory(CoroutineCallAdapterFactory())
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build()
ooh, I think this is the problem I thought it was the same as CoroutineCallAdapterFactory
Sorry, my bad it's fixed now
Thank you for fast response