Array/List in JSON
Let’s assume we have the JSON that presents a list or array of books.
We need to convert that JSON to a Java object with GSON (GSON Array or GSON List).
The regular approach described in JSON with GSON works as well
We can use the class we defined in Print Java objects in JSON format. Pay attention toString() method.
JSON to Array. GSON array
JSON to List. GSON list
Complete example JSON to List and JSON to Array
Real Java code with GSON List and GSON Array can look
Here we converted a string in JSON format which is just a list of books to Java Array and Java List with GSON. Then we converted them back to JSON. Execution gives us that console output
You may also find these posts interesting: