最近我从gsonconverterfactory切换到了莫斯科佛经。除一个电话外,每件事都很好。像其他API电话一样 java.lang.illegalargumentException:无法为class
创建 @body Converter我的请求类:
data class DemoRequest(
val emailId: String? = null,
val demoData: List<DemoDomain?>? = null,
val userName: String? = null
)
在这里还有一件事要说的是,使用gsonconverterfactory效果很好,但是当我切换到moshiconverterfactory时,它正在投掷错误。
retrofitversion ='2.3.0'
服务接口:
@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()
更新-------------------------------我在请求中发送日期对象,因此我需要使用自定义适配器,现在正常工作
您是否记得在构建Raturofit时要更改为MoshiConverterFactory
?
Retrofit.Builder().baseUrl(...).addConverterFactory(MoshiConverterFactory.create()).build()
另外,最新版本的翻新为2.5.0,因此您可以尝试升级并确保转换器也是相同的版本。