From ce4f7564464424ecb024451a55d631b872f790c1 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Sat, 24 Jul 2021 19:37:51 +0200 Subject: [PATCH] ServerPropertyFile now serializes with pretty printing --- .../fr/pandacube/lib/core/util/ServerPropertyFile.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Core/src/main/java/fr/pandacube/lib/core/util/ServerPropertyFile.java b/Core/src/main/java/fr/pandacube/lib/core/util/ServerPropertyFile.java index af30a25..373ad51 100644 --- a/Core/src/main/java/fr/pandacube/lib/core/util/ServerPropertyFile.java +++ b/Core/src/main/java/fr/pandacube/lib/core/util/ServerPropertyFile.java @@ -8,9 +8,12 @@ import java.io.FileWriter; import java.io.IOException; import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import com.google.gson.JsonSyntaxException; public class ServerPropertyFile { + + private static final Gson SERIALIZER = new GsonBuilder().setPrettyPrinting().create(); private transient File file; @@ -36,7 +39,7 @@ public class ServerPropertyFile { public boolean loadFromFile() { try (BufferedReader in = new BufferedReader(new FileReader(file))) { - ServerPropertyFile dataFile = new Gson().fromJson(in, getClass()); + ServerPropertyFile dataFile = SERIALIZER.fromJson(in, getClass()); name = dataFile.name; memory = dataFile.memory; @@ -58,10 +61,8 @@ public class ServerPropertyFile { public boolean save() { try (BufferedWriter out = new BufferedWriter(new FileWriter(file, false))) { - - new Gson().toJson(this, out); + SERIALIZER.toJson(this, out); out.flush(); - return true; } catch (IOException e) { Log.severe(e);