diff options
author | Keuin <[email protected]> | 2024-01-20 18:54:10 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2024-01-20 19:05:25 +0800 |
commit | 44227db56e3669b6b1575bf750df815e6903c906 (patch) | |
tree | 57c7a5503659aa0676119d7a9bdb48164fa6724f /src/main/java/com/keuin/kbackupfabric/config | |
parent | 7e3cd92742383c43f2741449c551208e6487154e (diff) |
feature: config file support JSON comment
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/config')
-rw-r--r-- | src/main/java/com/keuin/kbackupfabric/config/KBackupConfig.java | 11 |
1 files changed, 8 insertions, 3 deletions
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() { } |