The JSON is invalid. A collection is not to be represented by {}. It stands for an object. A collection/array is to be represented by [] with commaseparated objects.
Here's how the JSON should look like:
{
users:[{
name: "name1",
email: "email1",
friends:[{
name: "name2",
email: "email2",
friends:[{
name: "name3",
email: "email3"
},
{
name: "name4",
email: "email4"
}]
}]
}]
}
(note that I added one more friend to the deepest nested friend, so that you understand how to specify multiple objects in a collection)
Given this JSON, your wrapper class should look like this:
public class Data {
private List<User> users;
// +getters/setters
}
public class User {
private String name;
private String email;
private List<User> friends;
// +getters/setters
}
and then to convert it, use
Data data = gson.fromJson(this.json, Data.class);
and to get the users, use
List<User> users = data.getUsers();
Answer from BalusC on Stack OverflowJavadoc.io
javadoc.io › doc › com.google.code.gson › gson › 2.8.5 › com › google › gson › Gson.html
Gson - gson 2.8.5 javadoc
Bookmarks · Latest version of com.google.code.gson:gson · https://javadoc.io/doc/com.google.code.gson/gson · Current version 2.8.5 · https://javadoc.io/doc/com.google.code.gson/gson/2.8.5 · package-list path (used for javadoc generation -link option) · https://javadoc.io/doc/com.goog...
GitHub
google.github.io › gson › UserGuide.html
Gson User Guide | gson
Gson gson = new Gson(); int[] ints = {1, 2, 3, 4, 5}; String[] strings = {"abc", "def", "ghi"}; // Serialization gson.toJson(ints); // ==> [1,2,3,4,5] gson.toJson(strings); // ==> ["abc", "def", "ghi"] // Deserialization int[] ints2 = gson.fromJson("[1,2,3,4,5]", int[].class); // ==> ints2 will be same as ints
Videos
02:44
How to convert JSON to Java objects using Gson - YouTube
32:51
Reading and Writing JSON File Using Gson - YouTube
12:06
Handling JSON Files in Java | Gson Library | Part 6 - YouTube
07:37
Gson - How to convert Java object to / from JSON - YouTube
01:48
Resolving Gson's fromJson Method Returning Null for Complex JSON ...
09:30
Gson Tutorial — Getting Started with Java-JSON Serialization ...
Stack Overflow
stackoverflow.com › questions › 55971802 › how-does-gson-fromjsonstring-class-work
java - How does Gson.fromJson(String, Class) work? - Stack Overflow
I doubt this json + pojo work together. Just checked: If you add a toString to Info the output will be "Info{name=null, father=null, mother=null}" which is as expected because Gson (as expected) cannot map anything here.
TutorialsPoint
tutorialspoint.com › differences-between-fromjson-and-tojson-methods-of-gson-in-java
Differences between fromJson() and toJson() methods of Gson in Java?
May 13, 2025 - Here is the syntax of the fromJson() method: gson.fromJson(json, Person.class); The toJson() method is used to convert a Java object into a JSON string. It takes one parameter: the Java object you want to convert.
Javadoc.io
javadoc.io › doc › com.google.code.gson › gson › latest › com.google.gson › com › google › gson › Gson.html
Gson - gson 2.13.2 javadoc
Bookmarks · Latest version of com.google.code.gson:gson · https://javadoc.io/doc/com.google.code.gson/gson · Current version 2.13.2 · https://javadoc.io/doc/com.google.code.gson/gson/2.13.2 · package-list path (used for javadoc generation -link option) · https://javadoc.io/doc/com.go...
GitHub
github.com › google › gson
GitHub - google/gson: A Java serialization/deserialization library to convert Java Objects into JSON and back · GitHub
The Moshi APIs may be more familiar to users who already know Gson. If you still want to use Gson and attempt to avoid these crashes, you can see how to do so here. Provide simple toJson() and fromJson() methods to convert Java objects to JSON and vice-versa ·
Starred by 24.3K users
Forked by 4.4K users
Languages Java
Baeldung
baeldung.com › home › java › java list › serializing and deserializing a list with gson
Serializing and Deserializing a List with Gson | Baeldung
February 19, 2026 - @Test public void givenJsonString_whenDeserializing_thenReturnListOfMyClass() { String inputString = "[{\"id\":1,\"name\":\"name1\"},{\"id\":2,\"name\":\"name2\"}]"; List<MyClass> inputList = Arrays.asList(new MyClass(1, "name1"), new MyClass(2, "name2")); Type listOfMyClassObject = new TypeToken<ArrayList<MyClass>>() {}.getType(); Gson gson = new Gson(); List<MyClass> outputList = gson.fromJson(inputString, listOfMyClassObject); assertEquals(inputList, outputList); } Here, we use Gson’s TypeToken to determine the correct type to be deserialized – ArrayList<MyClass>. The idiom used to get the listOfMyClassObject actually defines an anonymous local inner class containing a method getType() that returns the fully parameterized type.
Attacomsian
attacomsian.com › blog › gson-read-json-file
How to read JSON from a file using Gson in Java
October 14, 2022 - The following example shows how you can read the above JSON file into a User object by using the fromJson() method: try { // create Gson instance Gson gson = new Gson(); // create a reader Reader reader = Files.newBufferedReader(Paths.get("user.json")); // convert a JSON string to a User object User user = gson.fromJson(reader,User.class); // print user object System.out.println(user); // close reader reader.close(); } catch (Exception ex) { ex.printStackTrace(); } You should see the following output printed on the console: User{name='John Doe', email='john.doe@example.com', roles=[Member, Adm
Baeldung
baeldung.com › home › json › convert string to jsonobject with gson
Convert String to JsonObject with Gson | Baeldung
May 5, 2025 - In this tutorial, we’ll learn how Gson can give us a JsonObject from a String.
Adobe Developer
developer.adobe.com › experience-manager › reference-materials › 6-5 › javadoc › com › google › gson › Gson.html
Gson (The Adobe AEM Quickstart and Web Application.)
This method deserializes the specified Json into an object of the specified type. This method is useful if the specified object is a generic type. For non-generic objects, use fromJson(String, Class) instead.
Maven Repository
mvnrepository.com › artifact › com.google.code.gson › gson
Maven Repository: com.google.code.gson » gson
September 10, 2025 - Gson is a Java library that can be used to convert Java Objects into their JSON representation.
TutorialsPoint
tutorialspoint.com › gson › gson_quick_guide.htm
GSON - Quick Guide
GsonBuilder builder = new GsonBuilder(); builder.setPrettyPrinting(); Gson gson = builder.create(); Use fromJson() method to get the Object from the JSON. Pass Json string / source of Json string and object type as parameter.