Retrofit issue with Coroutine
See original GitHub issuehi
i use retrofit 2.6.0, with kotlin coroutines 1.2.1,
- so when use Flow an exception appear:
@GET("/") suspend fun fetch(): Flow<User>
Exception in thread "main" com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `kotlinx.coroutines.flow.Flow`
- i have this case
GET("/{id}") suspend fun loadBy(@Path("id") id: Int): User?
if suppose that the back-end return NotFoundException(…) in failure, so the front-end (client) have an exception of can’t cast NotFoundException to User instance (font-end suppose receive a null instance of User in failure) so its possible to use Result<User> instead of User? nullable type however when try to use it i see kotlin not allow Result as return type
- even if try to use Result<User> instead of User?, an other exception appear:
Exception in thread "main" com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `kotlin.Result` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Kotlin Coroutines and Retrofit - Medium
Okay so Retrofit is a type-safe HTTP client for Android and Java. ... which uses Kotlin coroutine's Deferred type if you're using a...
Read more >Retrofit with Kotlin Coroutine in Android - GeeksforGeeks
Retrofit is a type-safe http client which is used to retrieve, update and delete the data from web services. Nowadays retrofit library is ......
Read more >Retrofit — Effective error handling with Kotlin Coroutine and ...
When the OkHttp client receives a response from the server, it passes the response back to the Retrofit. Retrofit then pushes the meaningless...
Read more >Suspend what you're doing: Retrofit has now Coroutines ...
It official now! Retrofit 2.6.0 has been released with support for suspend functions. This allows you to express the asynchrony of HTTP requests ......
Read more >Coroutines, Retrofit, and a nice way to handle Responses
An asynchronous programming pattern implemented with coroutines to perform “one-shot calls”. Regarding Android App Architecture our Service and Repository ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

backend-side (developed with NESTJS)
in front-end (retrofit client):
so when client send request to server to find user by id it expect to return user or null if not found, but in server side when user not found, server return exception of [NotFoundException] as response, so when client receive response (NotFoundException) it can’t cast it to User nullable instance and throw an exception of casting error
You would have to build it yourself. Retrofit only supports
suspendfunctions for coroutines, not Flow.