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

View File

@ -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<EnumMap<Direction, Face>>(){}.getType(),
new EnumMapInstanceCreator<Direction, Face>(Direction.class)
)
.create();
);
}
public static String nextStringOrBoolean(JsonReader in) throws IOException {