(Upgrade) Could not find converter for class breakdown application

So, Retrofit 2.0.0 was recently released, and in fact there are no updated examples of how to use it, but I'm trying to implement it for a basic API call. I get

java.lang.IllegalArgumentException: Unable to create converter for class` 

caused by

 Caused by: java.lang.IllegalArgumentException: Could not locate converter for class orbyt.app.dataclass. Tried: * retrofit.OkHttpBodyConverterFactory 

When trying to make an api call.

+75
java android retrofit
Sep 02 '15 at 1:10
source share
6 answers

I ran into the same problem. I fixed this by adding:

 compile 'com.squareup.retrofit2:converter-gson:<latest-version>' 

in my build.gradle

Then specify the converter when creating my Retrofit instance.

 Retrofit retrofit = new Retrofit.Builder() .baseUrl(Constants.API_BASE_URL) .addConverterFactory(GsonConverterFactory.create()) .build(); 
+125
Sep 02 '15 at 12:46
source share

In Retrofit 2.0, the converter is not included in the package and when using Retrofit 2.0 Make Sure, a new URL pattern follows

Base URL: always ends with /

@Url: DO NOT start with /

 Retrofit retrofit = new Retrofit.Builder() .baseUrl(Constants.API_BASE_URL) .addConverterFactory(GsonConverterFactory.create()) .build(); 

For more information about version 2.0 Follow this link Retrofit 2.0: The biggest update

Also update build.gradle.

+14
Sep 18 '15 at 13:03
source share

Change the modified version accordingly

For me, the addiction was already there.

 compile 'com.squareup.retrofit2:retrofit:2.0.2' 

For gson 2.0.2 I changed

 compile 'com.squareup.retrofit2:converter-gson:2.0.2' 

Then add

 Retrofit retrofit = new Retrofit.Builder() .baseUrl(Constants.API_BASE_URL) .addConverterFactory(GsonConverterFactory.create()) .build(); 
+7
Apr 17 '16 at 13:01
source share

For Retrofit V2, add the following repositories -

 compile 'com.squareup.retrofit2:retrofit:2.0.0' compile 'com.google.code.gson:gson:2.6.2' compile 'com.squareup.retrofit2:converter-gson:2.0.0' 

Now use below code -

 Retrofit retrofit = new Retrofit.Builder() .baseUrl(API_URL) .addConverterFactory(GsonConverterFactory.create()) .build(); 

Hope this helps :)

+6
Mar 21 '16 at
source share

In the latest version of Retrofit 2.0, you must import the latest version:

 compile 'com.squareup.retrofit2:retrofit:2.0.0' compile 'com.squareup.retrofit2:converter-gson:2.0.0' compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0' 

Be careful, call baseUrl() , in version 2.0, this should be the end of "/", and in this method you would start the trag with "/"

 @POST("classes/info") Call<ContactBean> insertInfo(@Body ContactBean bean); 

And you can see Retrofit to get more information! Hope to help!

+3
Mar 22 '16 at 10:20
source share

In my case (Kotlin with coroutines) I got an exception:

Unable to create converter for retrofit2.Call

for the Queries.exportPdf method.

Reason: java.lang.IllegalArgumentException: Could not find ResponseBody converter for retrofit2.Call

The problem was in the request:

 @FormUrlEncoded @Streaming @POST("export-pdf/") suspend fun exportPdf( @Field("token") token: String ): Call<ResponseBody> 

Removed suspend from the definition and exceptions disappeared.

0
Jul 18 '19 at 15:54
source share



All Articles