Foso / Ktorfit

HTTP client generator / KSP plugin for Kotlin Multiplatform (Android, iOS, Js, Jvm, Native, WasmJs)) using KSP and Ktor clients inspired by Retrofit https://foso.github.io/Ktorfit
https://foso.github.io/Ktorfit
Apache License 2.0
1.61k stars 43 forks source link

NoTransformationFoundException - expected kotlin.Boolean but found kotlin.Boolean #744

Open padmalcom opened 6 days ago

padmalcom commented 6 days ago

Ktorfit version

2.2.0

What happened and how can we reproduce this issue?

Hi I have this simple REST endpoint in my backend application:

@GetMapping("/api/v1/user/existsByEmail/{email}")
fun userExistsByEmail(@PathVariable("email") email: String) : ResponseEntity<Boolean> {
    return ResponseEntity.ok().body(userService.emailExists(email))
}

My ktorfit client look like that:

@GET(Endpoints.USER_EMAIL_EXISTS)
suspend fun userExistsByEmail(
    @Path("email") email: String
): Response<Boolean>

When calling the endpoint from the client I get a strange error message which is:

io.ktor.client.call.NoTransformationFoundException: Expected response body of the type 'class kotlin.Boolean' but was 'class kotlin.Boolean' In response from http://10.0.2.2:8080/api/v1/user/existsByEmail/jonas@test.de Response status 200 Response header ContentType: application/json Request header Accept: application/json

What did you expect to happen?

I'd expect ktorfit to parse the result as boolean wrapped as response successfully.

Is there anything else we need to know about?

Additional finding: When I remove the Response wrapper arount the Boolean, the endpoint works fine.

I already posted a KTOR issue but the devs could not reproduce it and mentioned to file a bug here because it might be ktorfit related: https://youtrack.jetbrains.com/issue/KTOR-7835/NoTransformationFoundException-expected-kotlin.Boolean-but-found-kotlin.Boolean

padmalcom commented 4 days ago

Found out today: When I remove the Response wrapper arount the Boolean, the endpoint works fine. Interesting is: If there is a complex object wrapped in the Response, the API works fine.