import java.util.ArrayList; import com.google.gson.Gson; import com.google.gson.GsonBuilder; public class App { public static void main(String[] args) throws Exception { Employee emp1 = new Employee("Csendes Imre", "Szeged", 342); Employee emp2 = new Employee("Gépi Roland", "Szeged", 345); ArrayList empList = new ArrayList<>(); empList.add(emp1); empList.add(emp2); GsonBuilder builder = new GsonBuilder(); builder.setPrettyPrinting(); Gson gson = builder.create(); String jsonStr = gson.toJson(empList.toArray()); System.out.println(jsonStr); } }