Retrofit已经为用户提供了六种Converter,如下:
- Gson:
com.squareup.retrofit2:converter-gson- Jackson:
com.squareup.retrofit2:converter-jackson- Moshi:
com.squareup.retrofit2:converter-moshi- Protobuf:
com.squareup.retrofit2:converter-protobuf- Wire:
com.squareup.retrofit2:converter-wire- Simple XML:
com.squareup.retrofit2:converter-simplexml- Scalars (primitives, boxed, and String):
com.squareup.retrofit2:converter-scalars

本文介绍了如何在使用Retrofit时,针对特定需求自定义Converter。默认的Converter无法满足发送String且接收JSON的情况,因此我们创建了两个单独的Converter:一个用于将请求体转换为String,另一个用于将响应体从JSON解析。通过组合现有的String和JSON Converter,实现了自定义的转换逻辑。完成设置后,可以在初始化Retrofit时应用这个自定义的Converter工厂。

1万+

被折叠的 条评论
为什么被折叠?



