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"}Top in Developer Tools
Related Repositories
Discover similar tools and frameworks used by developers
Gemini CLI
CLI for Google Gemini AI with text, image, and multimodal interactions from terminal.
Pino
Low-overhead streaming JSON logger for Node.js.
Nano ID
Compact 21-character cryptographic IDs with URL-safe encoding.
EPG
Node.js toolkit for downloading EPG data from hundreds of TV sources into standardized XML format.
Hugo
Fast static site generator written in Go with built-in asset processing and multiple content formats.