Code Monkey home page Code Monkey logo

Comments (6)

leonardoxh avatar leonardoxh commented on May 18, 2024

Do you have a converter for your GithubResponse (like gson, jackson, moshi) ? You should add it after the live data response body converter.

from livedata-call-adapter.

fazalBykea avatar fazalBykea commented on May 18, 2024

Yes, When I add GsonConverterFactory it gives me error that require retrofit2.Converter.factory but found retrofit.Converter.factory

from livedata-call-adapter.

leonardoxh avatar leonardoxh commented on May 18, 2024

this is not a library problem. This is a project setup problem. If you can provide a full related files I can help you.

from livedata-call-adapter.

leonardoxh avatar leonardoxh commented on May 18, 2024

Also you problem is that you are using the wrong gson converter factory dependency you should use the version two (retrofit2) instead of v1.

from livedata-call-adapter.

fazalBykea avatar fazalBykea commented on May 18, 2024

Ok. Please have a look.

My Service Interface

public interface IRestClient {

    @GET(ApiTags.GET_ORGANIZATION)
    LiveData<Resource<GithubResponse>> getGithubOrganization();
}

RestClient

public static Retrofit getClient(){
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(ApiTags.BASE_URL)
                .addCallAdapterFactory(LiveDataCallAdapterFactory.create())
                .addConverterFactory(LiveDataResponseBodyConverterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        return retrofit;
    }

Request Handler

public void requestGithubData(LifecycleOwner context, final IResponseCallback iResponseCallback) {
        this.context = context;
        mRestClient = RestClient.getClient();
        mRestClient.create(IRestClient.class).getGithubOrganization().observe(context,
                new Observer<Resource<GithubResponse>>() {
                    @Override
                    public void onChanged(@Nullable Resource<GithubResponse> githubResponseResource) {
                        if (githubResponseResource.isSuccess()){
                            iResponseCallback.onResponse(githubResponseResource.getResource());
                        }else {
                            iResponseCallback.onError(githubResponseResource.getError().hashCode(), githubResponseResource.getError().getMessage());
                        }
                    }
                });

    }

from livedata-call-adapter.

fazalBykea avatar fazalBykea commented on May 18, 2024

You are right! I am using retrofit v1 instead of v2. Thanks

from livedata-call-adapter.

Related Issues (2)

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.