Android java.lang.IllegalArgumentException:无法为类创建@Body转换器
最近我从GSONConverterFactory转到了MoshiConverterFactory。除了一个电话,其他一切都很好。和这里的其他API调用一样,我也在使用@Body注释,但我遇到了这个错误 java.lang.IllegalArgumentException:无法为类创建@Body转换器 我的请求类:Android java.lang.IllegalArgumentException:无法为类创建@Body转换器,android,retrofit2,moshi,Android,Retrofit2,Moshi,最近我从GSONConverterFactory转到了MoshiConverterFactory。除了一个电话,其他一切都很好。和这里的其他API调用一样,我也在使用@Body注释,但我遇到了这个错误 java.lang.IllegalArgumentException:无法为类创建@Body转换器 我的请求类: data class DemoRequest( val emailId: String? = null, val demoData: List<DemoDomain?>?
data class DemoRequest(
val emailId: String? = null,
val demoData: List<DemoDomain?>? = null,
val userName: String? = null
数据类DemoRequest(
val emailId:String?=null,
val解调数据:列表?=null,
val用户名:字符串?=null
)
这里还有一件事要提的是,使用GSONConverterFactory,它工作得很好,但当我切换到MoshiConverterFactory时,它抛出了错误
更新版本='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()
@POST(“调用/api”)
fun sendToServer(@Body request:DemoRequest):2.Call
val reformation=reformation.Builder()
.baseUrl(基本URL)
.客户(okHttpClient)
.addConverterFactory(MoshiConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build()
更新-------------
我在请求中发送了Date对象,因此我需要使用自定义适配器,它现在工作正常您是否记得在构建改装时更改为
MoshiConverterFactory
改装.Builder().baseUrl(…).addConverterFactory(MoshiConverterFactory.create()).build()
此外,最新版本的改型是2.5.0,因此您可以尝试升级,并确保转换器也是相同的版本。其他服务器调用工作正常。只有此呼叫导致问题。