Reputation: 583
Recently I switched to MoshiConverterFactory from GSONConverterFactory. Every thing s working fine except the one call. Like other API calls here also I am using @Body annotation but I am getting this error java.lang.IllegalArgumentException: Unable to create @Body converter for class
my request class :
data class DemoRequest(
val emailId: String? = null,
val demoData: List<DemoDomain?>? = null,
val userName: String? = null
)
One more thing here to mention that with GSONConverterFactory it is working fine but as I switched to MoshiConverterFactory it is throwing error.
retrofitVersion = '2.3.0'
service interface:
@POST("call/api")
fun sendToServer(@Body request: DemoRequest):retrofit2.Call<RemoteResponse>
val retrofit = Retrofit.Builder()
.baseUrl(BASE_URL)
.client(okHttpClient)
.addConverterFactory(MoshiConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build()
UPDATE------------- I was sending Date object in request so I need to use custom adapter and it is working fine now
Upvotes: 3
Views: 4792
Reputation: 701
Did you remember to change to MoshiConverterFactory
when you build Retrofit?
Retrofit.Builder().baseUrl(...).addConverterFactory(MoshiConverterFactory.create()).build()
Also, the latest version of Retrofit is 2.5.0 so you could try upgrading and make sure your converter is also the same version.
Upvotes: 1