From ad42f3ff857bbaa07157e013ba37dbceacebad85 Mon Sep 17 00:00:00 2001 From: Friederike von Gruben Date: Wed, 18 Jan 2023 22:23:44 +0100 Subject: [PATCH] Added writeObject method to the JSON Parser to write json objects --- .../java/org/bitbiome/classes/JsonParser.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/bitbiome/classes/JsonParser.java b/src/main/java/org/bitbiome/classes/JsonParser.java index be0e9b8..56a9535 100644 --- a/src/main/java/org/bitbiome/classes/JsonParser.java +++ b/src/main/java/org/bitbiome/classes/JsonParser.java @@ -2,8 +2,14 @@ package org.bitbiome.classes; import org.json.JSONObject; import org.json.JSONTokener; +import org.json.JSONWriter; +import java.io.FileWriter; +import java.io.IOException; import java.io.InputStream; +import java.io.StringWriter; + + public class JsonParser { @@ -30,7 +36,20 @@ public class JsonParser { } JSONTokener tokener = new JSONTokener(is); - return new JSONObject(tokener); } + + public static void writeObject(String fileName, JSONObject object) { + + String resourceName = System.getProperty("user.dir") + "/src/main/resources/" + fileName; + try { + FileWriter fw = new FileWriter(resourceName, false); + fw.write(object.toString(1)); + fw.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + + + } }