Gson: Java JSON serialization and deserialization library
Reflection-based Java library for JSON object conversion.
Learn more about gson
Gson is a Java library for converting between Java objects and JSON format. It uses reflection-based serialization to work with arbitrary Java objects, including pre-existing classes without access to source code. The library handles generic types, nested objects, and inheritance hierarchies through its type adapter system. Gson is commonly used in server-side Java applications, though the maintainers recommend alternative libraries for Android development due to reflection incompatibility with code obfuscation.
Zero-Annotation Object Mapping
Works with arbitrary Java objects without requiring source code modifications or annotations. Serializes third-party libraries and legacy classes directly, unlike frameworks that mandate interface implementation or metadata declarations.
Full Generic Type Preservation
Maintains complete type information for parameterized collections and complex generic hierarchies during serialization. TypeToken API captures runtime generic types that Java's erasure normally discards, enabling type-safe deserialization of List<String> versus List<Integer>.
Reflection-Based Introspection
Uses runtime reflection for automatic object traversal without code generation or compilation steps. Simplifies integration and supports dynamic class structures, though incompatible with aggressive obfuscation tools like R8 or ProGuard in Android release builds.
import com.google.gson.Gson;
class User {
String name;
String email;
}
Gson gson = new Gson();
User user = new User();
user.name = "John Doe";
user.email = "john@example.com";
String json = gson.toJson(user);
// {"name":"John Doe","email":"john@example.com"}Maintenance release updating dependencies and fixing JPMS module declaration so Eclipse and VS Code can resolve `com.google.gson`.
- –Update builds using Eclipse or VS Code to pick up the corrected JPMS module packaging that resolves `com.google.gson` references.
- –No breaking changes or new requirements; internal refactoring removed `GsonPreconditions` class and switched Maven publishing plugin.
Maintenance release updates Error Prone annotations dependency and adds multi-name support to FieldNamingStrategy.
- –Update to com.google.errorprone:error_prone_annotations:2.37.0 to resolve dependency issues.
- –FieldNamingStrategy can now return multiple field names for deserialization flexibility.
Breaking: Gson now enforces exact collection types during deserialization; code using TypeToken with abstract types like ImmutableList will fail.
- –Register a TypeAdapter or change TypeToken to concrete types (e.g., List instead of ImmutableList) to avoid JsonIOException on abstract collections.
- –Internal classes $Gson$Types and $Gson$Preconditions renamed without $ prefix; copy them locally if your code referenced these internal APIs.
See how people are using gson
Top in Backend & APIs
Related Repositories
Discover similar tools and frameworks used by developers
magento2
Modular PHP platform for self-hosted ecommerce storefronts.
express
Middleware-based HTTP routing and response handling for Node.js.
dompdf
CSS 2.1 compliant HTML layout and rendering engine.
gin
Fast HTTP router with JSON binding and middleware support.
rails
Convention-driven Ruby framework for full-stack web applications.