1 package net.mograsim.logic.ui.model.components.params;
3 import java.io.FileReader;
4 import java.io.FileWriter;
5 import java.io.IOException;
7 import com.google.gson.Gson;
8 import com.google.gson.GsonBuilder;
10 public class JsonHandler
12 private static Gson parser = new GsonBuilder().setPrettyPrinting().create();
14 @SuppressWarnings("resource")
15 public static <T> T readJson(String path, Class<T> type) throws IOException
17 FileReader reader = new FileReader(path);
18 T params = parser.fromJson(new FileReader(path), type);
23 public static void writeJson(Object o, String path) throws IOException
25 @SuppressWarnings("resource")
26 FileWriter writer = new FileWriter(path);
27 writer.write(parser.toJson(o));
28 writer.close(); // TODO: Insure that writer is closed