ServerPropertyFile now serializes with pretty printing

This commit is contained in:
Marc Baloup 2021-07-24 19:37:51 +02:00
parent 489b81e55f
commit ce4f756446
Signed by: marcbal
GPG Key ID: BBC0FE3ABC30B893
1 changed files with 5 additions and 4 deletions

View File

@ -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);