From 330f2cdbe256d949776eed94d7d7772c9c776f06 Mon Sep 17 00:00:00 2001 From: "Lukas Rieger (Blue)" Date: Sun, 31 Jul 2022 18:58:59 +0200 Subject: [PATCH] Pretty-print main settings file, to make manual editing easier --- .../bluemap/common/WebFilesManager.java | 6 +++++- .../core/resources/adapter/ResourcesGson.java | 14 ++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/WebFilesManager.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/WebFilesManager.java index 32bdc4d1..60f21a14 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/WebFilesManager.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/WebFilesManager.java @@ -24,6 +24,7 @@ */ package de.bluecolored.bluemap.common; +import com.google.gson.GsonBuilder; import de.bluecolored.bluemap.common.config.WebappConfig; import de.bluecolored.bluemap.core.logger.Logger; import de.bluecolored.bluemap.core.resources.adapter.ResourcesGson; @@ -65,7 +66,10 @@ public void saveSettings() throws IOException { Files.createDirectories(getSettingsFile().getParent()); try (BufferedWriter writer = Files.newBufferedWriter(getSettingsFile(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { - ResourcesGson.INSTANCE.toJson(this.settings, writer); + ResourcesGson.addAdapter(new GsonBuilder()) + .setPrettyPrinting() // enable pretty printing for easy editing + .create() + .toJson(this.settings, writer); } } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/adapter/ResourcesGson.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/adapter/ResourcesGson.java index bc9284ec..a87c0f3c 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/adapter/ResourcesGson.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/adapter/ResourcesGson.java @@ -17,12 +17,12 @@ public class ResourcesGson { - public static final Gson INSTANCE = createGson(); + public static final Gson INSTANCE = addAdapter(new GsonBuilder()) + .setLenient() + .create(); - private static Gson createGson() { - - return new GsonBuilder() - .setLenient() + public static GsonBuilder addAdapter(GsonBuilder builder) { + return builder .registerTypeAdapter(Axis.class, new AxisAdapter()) .registerTypeAdapter(Color.class, new ColorAdapter()) .registerTypeAdapter(Direction.class, new DirectionAdapter()) @@ -35,9 +35,7 @@ private static Gson createGson() { .registerTypeAdapter( new TypeToken>(){}.getType(), new EnumMapInstanceCreator(Direction.class) - ) - .create(); - + ); } public static String nextStringOrBoolean(JsonReader in) throws IOException {