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

In add. The documentation says:

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

This means that I would have to make a WIHTOUT api call using the GSON converter and get my answer as a ResponseBody object.

but i still get the 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, I want to use Retrofit in its purest / simplest form and just get a basic / raw response. it is not for a real application, it is for experimentation.

+5
source share
1 answer

You need to use okhttp3.ResponseBody from OkHttp 3.x (which depends on retrofitting). This error message indicates that you are using this type from OkHttp 2.x.

+3
source

Source: https://habr.com/ru/post/1259868/


All Articles