Skip to content
This repository has been archived by the owner on Jun 26, 2019. It is now read-only.

Unable to create converter for Resource #1

Closed
fazalBykea opened this issue Jul 21, 2018 · 6 comments
Closed

Unable to create converter for Resource #1

fazalBykea opened this issue Jul 21, 2018 · 6 comments

Comments

@fazalBykea
Copy link

I am following your Repository I am facing issue with converter factory.

Here is my code

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

        return retrofit;
    }

Logcat:

java.lang.IllegalArgumentException: Unable to create converter for com.github.leonardoxh.
livedatacalladapter.Resource<com.example.livedatademo.Models.response.GithubResponse>
                      for method IRestClient.getGithubOrganization
@leonardoxh
Copy link
Owner

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

@fazalBykea
Copy link
Author

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

@leonardoxh
Copy link
Owner

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

@leonardoxh
Copy link
Owner

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

@fazalBykea
Copy link
Author

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());
                        }
                    }
                });

    }

@fazalBykea
Copy link
Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants