Google's Java library for converting objects to and from JSON
open sourceApache-2.0free
Gson is Google's Java library for converting Java objects to JSON and back with toJson() and fromJson(). It works with arbitrary objects, including pre-existing classes you don't have the source for, without annotations, and fully supports Java generics and custom representations. It's in maintenance mode, and its README recommends a library with explicit support for Kotlin, and Kotlin Serialization on Android, where Gson's reflection clashes with code shrinking.
Problems it solves
- turn my Java objects into JSON and parse JSON back without annotating every class
- serialize objects from a third-party library I can't change to JSON in Java
- parse JSON into generic Java collections
Features
- convert Java objects to JSON and back with toJson and fromJson
- works with classes you can't annotate
- full support for Java generics
- custom serializers and type adapters
Limitations
Alternatives
The same job
These do what Gson does.
- Jackson The Java JSON library: a suite of data-processing tools for Java and the JVM
- FASTJSON 2 High-performance JSON library for Java, the successor to fastjson
- Moshi A modern JSON library for Android, Java and Kotlin
- JSON-java (org.json) The reference JSON implementation for Java, in the public domain
- json Ruby's JSON parser and generator, shipped with Ruby as a default gem
- Jayway JsonPath Query and update JSON documents in Java with XPath-like JsonPath expressions
