Pretty-print main settings file, to make manual editing easier

This commit is contained in:
Lukas Rieger (Blue) 2022-07-31 18:58:59 +02:00
parent ae992419bb
commit 330f2cdbe2
No known key found for this signature in database
GPG Key ID: 2D09EC5ED2687FF2
2 changed files with 11 additions and 9 deletions

View File

@ -24,6 +24,7 @@
*/ */
package de.bluecolored.bluemap.common; package de.bluecolored.bluemap.common;
import com.google.gson.GsonBuilder;
import de.bluecolored.bluemap.common.config.WebappConfig; import de.bluecolored.bluemap.common.config.WebappConfig;
import de.bluecolored.bluemap.core.logger.Logger; import de.bluecolored.bluemap.core.logger.Logger;
import de.bluecolored.bluemap.core.resources.adapter.ResourcesGson; import de.bluecolored.bluemap.core.resources.adapter.ResourcesGson;
@ -65,7 +66,10 @@ public void saveSettings() throws IOException {
Files.createDirectories(getSettingsFile().getParent()); Files.createDirectories(getSettingsFile().getParent());
try (BufferedWriter writer = Files.newBufferedWriter(getSettingsFile(), try (BufferedWriter writer = Files.newBufferedWriter(getSettingsFile(),
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { 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);
} }
} }

View File

@ -17,12 +17,12 @@
public class ResourcesGson { public class ResourcesGson {
public static final Gson INSTANCE = createGson(); public static final Gson INSTANCE = addAdapter(new GsonBuilder())
.setLenient()
.create();
private static Gson createGson() { public static GsonBuilder addAdapter(GsonBuilder builder) {
return builder
return new GsonBuilder()
.setLenient()
.registerTypeAdapter(Axis.class, new AxisAdapter()) .registerTypeAdapter(Axis.class, new AxisAdapter())
.registerTypeAdapter(Color.class, new ColorAdapter()) .registerTypeAdapter(Color.class, new ColorAdapter())
.registerTypeAdapter(Direction.class, new DirectionAdapter()) .registerTypeAdapter(Direction.class, new DirectionAdapter())
@ -35,9 +35,7 @@ private static Gson createGson() {
.registerTypeAdapter( .registerTypeAdapter(
new TypeToken<EnumMap<Direction, Face>>(){}.getType(), new TypeToken<EnumMap<Direction, Face>>(){}.getType(),
new EnumMapInstanceCreator<Direction, Face>(Direction.class) new EnumMapInstanceCreator<Direction, Face>(Direction.class)
) );
.create();
} }
public static String nextStringOrBoolean(JsonReader in) throws IOException { public static String nextStringOrBoolean(JsonReader in) throws IOException {