Code Monkey home page Code Monkey logo

retrofit2-kotlin-coroutines-call-adapter's Introduction

Retrofit CallAdapter for Coroutines to handle response as states

Checkout the article on Medium

retrofit2-kotlin-coroutines-call-adapter's People

Contributors

mlegy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

retrofit2-kotlin-coroutines-call-adapter's Issues

Failed to invoke private NetworkResponse() with no args

I'm using RxJava and the ApiService is like:

@POST("url")
fun createThing(...): Single<NetworkResponse<MyResponseModel, ErrorModel>

And I use it like:

retrofitThing.createApi()
    .subscribeOn(Schedulers.io)
    .subscribe({
    when(...
    },
    {
    //ERROR: java.lang.RuntimeException: Failed to invoke private NetworkResponse() with no args
    })

Then I get this error:

java.lang.RuntimeException: Failed to invoke private NetworkResponse() with no args

Unable to create call adapter for NetworkResponse<DogResponse, DogError>

I am trying to do the same thing in my application and i get the above exception when i do the request.
I am using

// Retrofit Requests
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
    implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'
    implementation 'com.squareup.retrofit2:converter-simplexml:2.8.1'

// Gson to Kotlin Object
    implementation 'com.google.code.gson:gson:2.8.6'

The apiInterface has this call method

@POST(DogsApiUrl)
suspend fun suspendDogsRequest(@Body dogRequest: DogRequest): NetworkResponse<DogResponse, DogError>

And i provide Rertofit through Dagger2 and

@Provides
    @Singleton
    internal fun provideRetrofit(client: OkHttpClient): Retrofit.Builder {
        return Retrofit.Builder()
            .addCallAdapterFactory(NetworkResponseAdapterFactory())
            .addConverterFactory(
                GsonConverterFactory.create(GsonBuilder().setLenient().create()))
            .client(client)
    }

I call the request like that

val dogs = apiManager.dogsApiService().suspendDogsRequest(
                DogRequest(Dog("pitbull", "Athens"))
            )

when (dogs) {
                is NetworkResponse.Success -> println("Success")
                is NetworkResponse.ApiError -> println("ApiError")
                is NetworkResponse.NetworkError -> println("NetWork Error")
                is NetworkResponse.UnknownError -> println("Unknown error")
            }

I can t understand why this does not work. What should i check?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.