🌐
GitHub
google.github.io › gson › UserGuide.html
Gson User Guide | gson
If the above mechanisms for excluding fields and class type do not work for you then you can always write your own exclusion strategy and plug it into Gson. See the ExclusionStrategy JavaDoc for more information. The following example shows how to exclude fields marked with a specific @Foo annotation and excludes top-level types (or declared field type) of class String.
🌐
HowToDoInJava
howtodoinjava.com › home › gson › gson tutorial: read and write json with examples
Gson Tutorial: Read and Write JSON with Examples
August 27, 2023 - Mapping of Sets – Learn to use Google GSON library to deserialize or parse JSON to Set (e.g. HashSet) in java. Mapping of Maps – Learn to serialize HashMap using Google Gson library. Also, learn to deserialize JSON strings to HashMap containing custom Objects using Gson such that field values are copied into appropriate generic types. The basic examples in the first part are good enough for default usecases.
open-source Java library to serialize and deserialize Java objects to and from JSON
Gson, or Google Gson, is an open-source Java library that serializes Java objects to JSON (and deserializes them back to Java). The Gson library was originally developed for internal purposes at Google, … Wikipedia
Factsheet
Google Gson
Developer Google
Initial release May 22, 2008; 17 years ago (2008-05-22)
Factsheet
Google Gson
Developer Google
Initial release May 22, 2008; 17 years ago (2008-05-22)
🌐
GitHub
github.com › google › gson
GitHub - google/gson: A Java serialization/deserialization library to convert Java Objects into JSON and back · GitHub
Older Gson versions may also support lower API levels, however this has not been verified. API Javadoc: Documentation for the current release · User guide: This guide contains examples on how to use Gson in your code
Starred by 24.3K users
Forked by 4.4K users
Languages   Java
🌐
Jenkov
jenkov.com › tutorials › java-json › gson.html
GSON - Java JSON Tutorial
February 18, 2016 - To use GSON version support you must first annotate your Java classes with the GSON @Since annotation. Here is an example Person class with its fields annotated with the @Since annotation:
🌐
Mkyong
mkyong.com › home › java › convert java objects to from json using gson
Convert Java objects to from JSON using Gson - Mkyong.com
May 6, 2024 - package com.mkyong.json.gson; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.mkyong.json.model.Staff; import java.io.FileReader; import java.io.IOException; import java.io.Reader; public class GsonConvertJsonToObject { public static void main(String[] args) { // default compact print Gson gson = new Gson(); try (Reader reader = new FileReader("staff.json")) { // Convert JSON File to Java Object Staff staff = gson.fromJson(reader, Staff.class); // print staff object System.out.println(staff); } catch (IOException e) { throw new RuntimeException(e); } } } ... Staff{name='mkyong', age=42, position=[Founder, CTO, Writer], skills=[java, python, node, kotlin], salary={2018=14000, 2012=12000, 2010=10000}, active=true} 5.2 The following example uses Gson to read from a JSON String and convert back to the Staff object.
🌐
TutorialsPoint
tutorialspoint.com › gson › gson_quick_guide.htm
GSON - Quick Guide
Student [ name: Mahesh, age: 21 ] { "name" : "Mahesh", "age" : 21 } Let's serialize a Java object to a Json file and then read that Json file to get the object back. In this example, we've created a Student class.
🌐
ZetCode
zetcode.com › java › gson
Java Gson - JSON serialization and deserialization in Java with Gson
October 10, 2024 - In the following example, we use the Gson tree model API to write Java objects into JSON.
🌐
HowToDoInJava
howtodoinjava.com › home › gson › gson tutorial: read and write json with examples
Gson Examples - Read and Write JSON in Java
August 27, 2023 - Excluding Fields From Serialization and Deserialization – Gson supports numerous mechanisms for excluding top-level classes, fields and field types. Learn how to use them. JsonReader – Streaming JSON parser – Learn to read a JSON string or file as a stream of JSON tokens. JsonParser, JsonElement and JsonObject – Learn to parse a JSON string or stream into a tree structure of Java objects into JsonElement.
Find elsewhere
🌐
Vogella
vogella.com › tutorials › JavaLibrary-Gson › article.html
Google Gson for converting Java objects to JSON and JSON to Java with - Tutorial
3 weeks ago - To fail the conversion is case an object is missing in the JSON, you could create and register a customer deserializer and annotation. See https://stackoverflow.com/a/21634867/548637 for an example. In this exercise, you use Gson to convert a data model into JSON and the JSON back to Java objects.
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-setup-gson-for-java-application
How to Setup GSON For Java Application? - GeeksforGeeks
August 30, 2021 - ... // Java Program to Make Rating ... of Gson and user-defined // Employee class Gson gson = new Gson(); Employee emp = new Employee(); emp.setName("Jane"); emp.setId("J01012"); emp.setDepar...
🌐
DZone
dzone.com › coding › frameworks › json handling with gson in java with oop essence
JSON Handling With GSON in Java With OOP Essence
January 4, 2024 - However, GSON, a powerful library developed by Google, can simplify the conversion between Java objects and JSON strings. This article will guide you through the basics of GSON, using practical examples, and show how Object-Oriented Programming (OOP) principles play a crucial role in this process.
🌐
Mkyong
mkyong.com › home › java › how to parse json using gson
How to parse JSON using Gson - Mkyong.com
May 2, 2024 - The following example uses Gson TypeToken to parse a JSON array and convert it to a list of objects List<Person>. ... package com.mkyong.json.gson; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.mkyong.jso...
🌐
Java Guides
javaguides.net › p › google-gson-tutorial.html
Google GSON Tutorial
March 2, 2022 - GSON - Serialize and Deserialize Collections Example - In this example, we serialize a collection of Integer and Employee objects into JSON representation and use the TypeToken to deserialize the collection of Integers into the arbitrary Java Object.
🌐
Twilio
twilio.com › en-us › blog › developers › tutorials › building-blocks › java-json-with-gson
Two ways to use Gson for JSON in Java | Twilio
June 13, 2025 - You might have noticed that I used closeApproachDate in my short example JSON above, where the data from NASA has close_approach_date. I did that because Gson will use Java’s reflection capabilities to match JSON keys to Java field names, and they need to match exactly.
🌐
Wikipedia
en.wikipedia.org › wiki › Gson
Gson - Wikipedia
October 30, 2025 - package main; import example.Person; import com.google.gson.Gson; public class Main { public static void main(String[] args) { Gson gson = new Gson(); String json = "{\"name\":\"John\",\"surname\":\"Doe\",\"cars\":[{\"manufacturer\":\"Audi\",\"model\":\"A4\"," + "\"capacity\":1.8,\"accident\":false},{\"manufacturer\":\"Škoda\",\"model\":\"Octavia\",\"capacity\"" + ":2.0,\"accident\":true}],\"phone\":2025550191}"; Person johnDoe = gson.fromJson(json, Person.class); System.out.println(johnDoe.toString()); } }
🌐
GitHub
github.com › janbodnar › Java-Gson-Examples
GitHub - janbodnar/Java-Gson-Examples: Java Gson examples from the Java Gson tutorial
Java Gson examples show how to work with JSON in Java using Gson library. We use three different Gson APIs to work with JSON.
Starred by 7 users
Forked by 4 users
Languages   Java 100.0% | Java 100.0%
🌐
GitHub
github.com › google › gson › blob › main › UserGuide.md
gson/UserGuide.md at master · google/gson
January 26, 2024 - If the above mechanisms for excluding fields and class type do not work for you then you can always write your own exclusion strategy and plug it into Gson. See the ExclusionStrategy JavaDoc for more information. The following example shows how to exclude fields marked with a specific @Foo annotation and excludes top-level types (or declared field type) of class String.
Author   google
🌐
TutorialsPoint
tutorialspoint.com › gson › index.htm
Google Gson Tutorial
This tutorial is tailored for readers who aim to understand and utilize Google GSON to process/modify JSON using Java programming language.
🌐
Javadoc.io
javadoc.io › doc › com.google.code.gson › gson › 2.8.0 › com › google › gson › Gson.html
Gson - gson 2.8.0 javadoc
Latest version of com.google.code.gson:gson · https://javadoc.io/doc/com.google.code.gson/gson · Current version 2.8.0 · https://javadoc.io/doc/com.google.code.gson/gson/2.8.0 · package-list path (used for javadoc generation -link option) https://javadoc.io/doc/com.google.code.gson/gso...