在Retrofit2中使用@Body注解时出现错误提示java.lang.IllegalArgumentException: Unable to create @Body converter for class xxxx (parameter #1),于是开始向百度谷歌求救,基本都是说要要添加转换器.addConverterFactory(GsonConverterFactory.create()),或者不能跟
@FormUrlEncoded一起使用,或者有加密的类容就要自定义转换器,
可是我明明是这样的,有没有加密,最后发现原来转换器要需要跟retrofit的版本对应,我原来的依赖是这样的
implementation \'io.reactivex.rxjava2:rxjava:2.1.0\'
implementation \'io.reactivex.rxjava2:rxandroid:2.0.1\'
implementation \'com.squareup.retrofit2:retrofit:2.3.0\'
compile \'com.squareup.retrofit2:converter-gson:2.0.0-beta3\'
implementation \'com.squareup.retrofit2:adapter-rxjava2:2.2.0\'
implementation \'org.greenrobot:eventbus:3.0.0\'
implementation \'com.squareup.okhttp3:logging-interceptor:3.3.1\'
后来把转换器的依赖版本改成2.3.0,如下所示:
implementation \'com.squareup.retrofit2:converter-gson:2.3.0\'
Retrofit中转换器的名称没有变,但是依赖路径变成这个了import retrofit2.converter.gson.GsonConverterFactory;
Retrofit retrofit = new Retrofit.Builder()
. Url(getUrl())
.client(okHttpClient)
//.addConverterFactory(GsonConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
总算可以了,心累,记录下来希望可已帮到有需要的人。
继续阅读与本文标签相同的文章
上一篇 :
RabbitMQ 消息中间件
-
2019云栖大会 | 开源数据库界大神集体现身,邀你共同感受“开源魅力”
2026-05-18栏目: 教程
-
陈冠希竟然和罗永浩联手了!难不成要搞个锤子?当然不是……
2026-05-18栏目: 教程
-
中国最强快递公司,年入300亿,被称作“哪都通”,但国人都很嫌弃
2026-05-18栏目: 教程
-
原厂直播:ANSYS SI/PI/EMI&TI 2019 R3 新功能介绍
2026-05-18栏目: 教程
-
距离死亡不到3个月 Win7被疯狂攻击
2026-05-18栏目: 教程
