Repolode
google

google/gson

A Java library for converting Java objects to JSON and back, including objects whose source code you don't have.

Stars
24,238
Forks
4,491
Open issues
340
Last commit
10 days ago

What is it?

Gson converts Java objects into JSON strings through simple toJson() and fromJson() methods, and can parse JSON back into equivalent Java objects. Unlike many alternatives, it does not require Java annotations on your classes, so it works with pre-existing or unmodifiable objects whose source code you cannot change.

The library puts strong emphasis on Java Generics, aiming to handle deeply nested objects, deep inheritance hierarchies and generic types. Developers can also define custom representations for objects when the default mapping is not suitable.

Gson is currently in maintenance mode: existing bugs get fixed, but large new features are unlikely to be added. The project focuses on Java; it is not recommended for Android release apps because its reflection-based runtime conflicts with code shrinking and obfuscation.

Key features

  • 01Converts Java objects to JSON with toJson() and back with fromJson()
  • 02Works with classes that have no source code or annotations
  • 03Extensive support for Java Generics
  • 04Allows custom serialization representations for objects
  • 05Handles deep inheritance hierarchies and complex nested objects

Use cases

  • Parsing JSON API responses into Java model classes
  • Serializing third-party or unmodifiable Java objects to JSON
  • Persisting Java object state as JSON files
  • Building Java backends that exchange JSON data

Quick start

  1. 1

    Add the Gson dependency to your Gradle build

    implementation 'com.google.code.gson:gson:2.14.0'
  2. 2

    Or add the Gson dependency to your Maven pom.xml

  3. 3

    Build the project from source with Maven

    mvn clean verify

Things to know

  • Gson is in maintenance mode, so large new features are unlikely to be added.
  • Gson is not recommended for JSON handling on Android because its reflection can break under shrinking and obfuscation.
  • Building from source requires JDK 17 or newer, and newer JDKs are not supported for building.

Topics

FAQ

What is gson?
A Java library for converting Java objects to JSON and back, including objects whose source code you don't have. Gson converts Java objects into JSON strings through simple toJson() and fromJson() methods, and can parse JSON back into equivalent Java objects. Unlike many alternatives, it does not require Java annotations on your classes, so it works with pre-existing or unmodifiable objects whose source code you cannot change.
Is gson free to use? What license does it have?
gson is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
Is gson still maintained?
Actively maintained. The last commit to gson was on Oct 11, 2026.
What can I use gson for?
Parsing JSON API responses into Java model classes Serializing third-party or unmodifiable Java objects to JSON Persisting Java object state as JSON files Building Java backends that exchange JSON data
How do I install gson?
Add the Gson dependency to your Gradle build: implementation 'com.google.code.gson:gson:2.14.0' Or add the Gson dependency to your Maven pom.xml Build the project from source with Maven: mvn clean verify
Where can I get gson?
The source code and installation instructions are on GitHub: https://github.com/google/gson

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects