Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to create converter for class com.squareup.okhttp.ResponseBody

Retrofit Documentation says:

"By default, Retrofit can only deserialize HTTP bodies into OkHttp's ResponseBody...Converters can be added to support other types"

This implies I should be able to make a api call WIHTOUT using the GSON converter, and get my response in the form of a "ResponseBody" object.

but I still get error

java.lang.IllegalArgumentException: Unable to create converter for class com.squareup.okhttp.ResponseBody

here is my code

    @GET("v1/search")
    Call<ResponseBody> getArtists(@Query("q") String name, @Query("type") String searchType);
    Retrofit retrofit = new Retrofit.Builder()
                    .baseUrl("https://api.spotify.com/")
                    .build();

    api = retrofit.create(SpotifyApi.class);

    api.getArtists(searchBox.getText().toString(), "artist")
                             .enqueue(new Callback<ResponseBody>() {
                                 @Override
                                 public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {

                                 }

                                 @Override
                                 public void onFailure(Call<ResponseBody> call, Throwable t) {

                                 }
                             });

Basically for I want to be able to use Retrofit in its purest/simplest form and just get a basic/raw response back. this is not for a real app, it's for experimentation.

like image 657
Siavash Avatar asked Nov 17 '16 00:11

Siavash


1 Answers

You need to use okhttp3.ResponseBody from OkHttp 3.x (which Retrofit depends on). That error message indicates you are using the type from OkHttp 2.x.

like image 82
Jake Wharton Avatar answered Oct 21 '22 19:10

Jake Wharton