改造2中的'com.google.code.gson:gson:2.6.1'依赖项在拥有自己的gson转换器时起什么作用? [英] What is the role of 'com.google.code.gson:gson:2.6.1' dependency in retrofit 2 when it has its own gson converter?
问题描述
// 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转换有关.如果添加了第三个依赖项,是否仍然需要第二个依赖项?
My question is regarding the second and third dependency added. I do understand it is related to JSON conversion. If the third dependency is added,would the second dependency still be needed?
我已经看到它们都被添加到几个示例中.例如: 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
I have seen them both being added on several examples. For e.g: 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
推荐答案
在源,其中包含Gson的依赖项.
At the source of Retrofit Gson contverter library, there is a dependency of Gson.
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
因此,当您将 com.squareup.retrofit2:converter-gson
作为依赖项时, com.google.code.gson:gson
将自动包含.
So, when you include com.squareup.retrofit2:converter-gson
as your dependency, com.google.code.gson:gson
will be automatically included.
因此,您无需显式包括 Gson
依赖项.
So, you will not need to include the Gson
dependency explicitly.
这篇关于改造2中的'com.google.code.gson:gson:2.6.1'依赖项在拥有自己的gson转换器时起什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!