aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/moe/ymc/acron/config/json/ConfigDeserializer.java
diff options
context:
space:
mode:
authorYuuta Liang <yuuta@yuuta.moe>2022-07-13 11:16:27 -0700
committerTrumeet <yuuta@yuuta.moe>2022-07-13 11:16:27 -0700
commit85045e1e4a15e0a5657d189e83dd202a2c37f2b0 (patch)
tree944bc9ee7a86bd413dfc940e210f21d2434ec7d3 /src/main/java/moe/ymc/acron/config/json/ConfigDeserializer.java
downloadacron-85045e1e4a15e0a5657d189e83dd202a2c37f2b0.tar
acron-85045e1e4a15e0a5657d189e83dd202a2c37f2b0.tar.gz
acron-85045e1e4a15e0a5657d189e83dd202a2c37f2b0.tar.bz2
acron-85045e1e4a15e0a5657d189e83dd202a2c37f2b0.zip
First Commit
Signed-off-by: Trumeet <yuuta@yuuta.moe>
Diffstat (limited to 'src/main/java/moe/ymc/acron/config/json/ConfigDeserializer.java')
-rw-r--r--src/main/java/moe/ymc/acron/config/json/ConfigDeserializer.java27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/main/java/moe/ymc/acron/config/json/ConfigDeserializer.java b/src/main/java/moe/ymc/acron/config/json/ConfigDeserializer.java
new file mode 100644
index 0000000..e91b355
--- /dev/null
+++ b/src/main/java/moe/ymc/acron/config/json/ConfigDeserializer.java
@@ -0,0 +1,27 @@
+package moe.ymc.acron.config.json;
+
+import com.google.gson.Gson;
+import moe.ymc.acron.config.Config;
+import org.jetbrains.annotations.NotNull;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
+
+public class ConfigDeserializer {
+ public static @NotNull Config deserialize(@NotNull File file, boolean startup)
+ throws ConfigDeserializationException, IOException {
+ final Reader reader = new FileReader(file);
+ final moe.ymc.acron.config.json.Config config;
+ try {
+ config = new Gson()
+ .fromJson(reader, moe.ymc.acron.config.json.Config.class);
+ } catch (Throwable e) {
+ throw new ConfigDeserializationException("Cannot parse JSON: " + e.getMessage(),
+ true);
+ }
+ reader.close();
+ return config.create(startup);
+ }
+}