android - 'com.google.code.gson:gson:2.6.1' 依赖在 retrofit 2 自带 gson 转换器的情况下有什么作用?

标签 android gson retrofit

// Retrofit
compile 'com.squareup.retrofit2:retrofit:2.1.0'

// JSON Parsing
compile 'com.google.code.gson:gson:2.6.1'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'

我的问题是关于添加的第二个和第三个依赖项。我知道它与 JSON 转换有关。如果加上第三个依赖,还需要第二个依赖吗?

我已经看到它们都被添加到几个示例中。 例如: https://www.androidhive.info/2016/05/android-working-with-retrofit-http-library/ https://code.tutsplus.com/tutorials/sending-data-with-retrofit-2-http-client-for-android--cms-27845

最佳答案

source Retrofit Gson converter library,有一个Gson的依赖。

<dependency>
  <groupId>com.google.code.gson</groupId>
  <artifactId>gson</artifactId>
</dependency>

因此,当您将 com.squareup.retrofit2:converter-gson 作为您的依赖项时,com.google.code.gson:gson自动包括在内

因此,您不需要显式地包含 Gson 依赖项。

关于android - 'com.google.code.gson:gson:2.6.1' 依赖在 retrofit 2 自带 gson 转换器的情况下有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49399098/

相关文章:

java - 用GSON解析JSON,对象有时包含列表有时包含对象

java - Android、Retrofit、RxJava - 将多个实体的字段合并为一个实体

android - MultipartBody.Part上传文件

java - 图像文件无法使用改造 2 后方法发送到服务器

android - 在Android浏览器上禁用图像下载

android - card.io 在生产中不起作用

kotlin - 我们可以依靠Gson修改val属性的能力吗?

android - 用于动态 json 键值的 Gson 解析器类 - Android

安卓 : Push data with notification

android - 有什么方法可以根据Android中RecyclerView的项目文本长度为每一行设置不同的 'spanCount'