From 44227db56e3669b6b1575bf750df815e6903c906 Mon Sep 17 00:00:00 2001 From: Keuin Date: Sat, 20 Jan 2024 18:54:10 +0800 Subject: feature: config file support JSON comment --- .../java/com/keuin/kbackupfabric/config/KBackupConfig.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/main/java/com/keuin/kbackupfabric/config/KBackupConfig.java') diff --git a/src/main/java/com/keuin/kbackupfabric/config/KBackupConfig.java b/src/main/java/com/keuin/kbackupfabric/config/KBackupConfig.java index 8ece8d2..8ce5ed4 100644 --- a/src/main/java/com/keuin/kbackupfabric/config/KBackupConfig.java +++ b/src/main/java/com/keuin/kbackupfabric/config/KBackupConfig.java @@ -1,6 +1,7 @@ package com.keuin.kbackupfabric.config; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; import com.keuin.kbackupfabric.util.PrintUtil; @@ -25,20 +26,24 @@ public class KBackupConfig { return new KBackupConfig(false); } - public static void load() throws IOException { - File file = new File(CONFIG_FILE); + public static void load(File file) throws IOException { ObjectMapper om = new ObjectMapper(); + om.enable(JsonParser.Feature.ALLOW_COMMENTS); try { instance = om.readValue(file, KBackupConfig.class); } catch (FileNotFoundException ignored) { // generate default config file - PrintUtil.info("Config file does not exist. Creating default config: " + CONFIG_FILE); + PrintUtil.info("Config file does not exist. Creating default config: " + file.getAbsolutePath()); instance = getDefault(); ObjectWriter w = om.writerWithDefaultPrettyPrinter(); w.writeValue(file, instance); } } + public static void load() throws IOException { + load(new File(CONFIG_FILE)); + } + public KBackupConfig() { } -- cgit v1.2.3