Gson library in Android Studio

Read Google-gson

Gson is a Java library that can be used to convert Java Objects into their JSON representation. It can also be used to convert a JSON string to an equivalent Java object.

Add the following line to your MODULE LEVEL build.gradle configuration:

dependencies {
     implementation 'com.google.code.gson:gson:2.8.8' // Old 2.8.6
}

Add following dependency to build.gradle:

implementation 'com.google.code.gson:gson:2.8.7'

Or download the JAR file from Maven by clicking a release and finding the .jar file.

Replace 2.8.7 with the latest version from Maven.

Visit the GitHub repo for documentation and more.


If you are going to use it with Retrofit library, I suggest you to use Square's gson library as:

implementation 'com.squareup.retrofit2:converter-gson:2.4.0'

Use gradle dependencies to get the Gson in your project. Your application build.gradle should look like this-

dependencies {
  implementation 'com.google.code.gson:gson:2.8.2'
}

Tags:

Android

Gson