Mario Andhika
07/31/2023, 2:21 AMHttpResponseValidator {
validateResponse { response ->
val body = Json.parseToJsonElement(response.bodyAsText())
val map = body.jsonObject.toMap()
if (map["status"].toString() != "\"${Status.SUCCESS.status}\"") {
throw Exception("API didn't return success")
}
}
}
Gets me
io.ktor.serialization.ContentConvertException: No suitable converter found for TypeInfotype=class asia.zeals.mobile.android.models.responses.HomeResponse (Kotlin reflection is not available), reifiedType=class asia.zeals.mobile.android.models.responses.HomeResponse, kotlinType=asia.zeals.mobile.android.models.responses.HomeResponse (Kotlin reflection is not available))
Commenting out the HttpResponseValidator, I don’t get the exception anymore. Is there anything else I’m supposed to do in the validator? I do have
@Serializable
data class HomeResponse(
val status: String,
val data: HomeSetData? = null
)
Aleksei Tirman [JB]
07/31/2023, 9:55 AMresponse.bodyAsText()
call inside the validateResponse
consumes the response body so it becomes empty anywhere else. This is a know issue (KTOR-4225).