Here you can find the source of saveToJson(Object object, String file)
public static void saveToJson(Object object, String file)
//package com.java2s; //License from project: Open Source License import com.google.gson.Gson; import com.google.gson.GsonBuilder; import java.io.FileWriter; import java.io.IOException; import java.io.Writer; public class Main { public static void saveToJson(Object object, String file) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); try {// w w w. j a v a 2 s . co m Writer writer = new FileWriter(file); writer.write(gson.toJson(object)); writer.close(); } catch (IOException e) { e.printStackTrace(); } } }