diff --git a/pom.xml b/pom.xml index 58a3aff..a826d46 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.b0at torsion - 0.2.0-SNAPSHOT + 0.3.0 diff --git a/src/main/java/net/b0at/torsion/FileStorage.java b/src/main/java/net/b0at/torsion/FileStorage.java index cbaf286..0a27e0d 100644 --- a/src/main/java/net/b0at/torsion/FileStorage.java +++ b/src/main/java/net/b0at/torsion/FileStorage.java @@ -7,10 +7,6 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; -/** - * Created by Jordin on 8/4/2017. - * Jordin is still best hacker. - */ public class FileStorage implements Storage { private static File baseDirectory = new File("."); private final File file; diff --git a/src/main/java/net/b0at/torsion/Storage.java b/src/main/java/net/b0at/torsion/Storage.java index 7a53a15..70424cb 100644 --- a/src/main/java/net/b0at/torsion/Storage.java +++ b/src/main/java/net/b0at/torsion/Storage.java @@ -1,9 +1,5 @@ package net.b0at.torsion; -/** - * Created by Jordin on 8/4/2017. - * Jordin is still best hacker. - */ public interface Storage { T load(); diff --git a/src/main/java/net/b0at/torsion/parser/StorageParser.java b/src/main/java/net/b0at/torsion/parser/StorageParser.java index c65a007..c303a1f 100644 --- a/src/main/java/net/b0at/torsion/parser/StorageParser.java +++ b/src/main/java/net/b0at/torsion/parser/StorageParser.java @@ -1,9 +1,5 @@ package net.b0at.torsion.parser; -/** - * Created by Jordin on 8/4/2017. - * Jordin is still best hacker. - */ public interface StorageParser { T load(Class clazz); diff --git a/src/main/java/net/b0at/torsion/parser/file/FileParserFactory.java b/src/main/java/net/b0at/torsion/parser/file/FileParserFactory.java index 5cf539e..3040efc 100644 --- a/src/main/java/net/b0at/torsion/parser/file/FileParserFactory.java +++ b/src/main/java/net/b0at/torsion/parser/file/FileParserFactory.java @@ -8,10 +8,6 @@ import java.lang.reflect.InvocationTargetException; import java.util.Map; -/** - * Created by Jordin on 8/4/2017. - * Jordin is still best hacker. - */ public class FileParserFactory { private static final Map> PARSER_MAP = ImmutableMap.>builder() .put("json", JSONFileParser.class) @@ -29,6 +25,6 @@ public static StorageParser from(File file, String extension) throws Instant Class parserClass = PARSER_MAP.getOrDefault(extension, NullFileParser.class); - return parserClass.getDeclaredConstructor(File.class).newInstance(file); + return parserClass.getDeclaredConstructor(File.class).newInstance(file); } } diff --git a/src/main/java/net/b0at/torsion/parser/file/FileStorageParser.java b/src/main/java/net/b0at/torsion/parser/file/FileStorageParser.java index 5490883..f78292b 100644 --- a/src/main/java/net/b0at/torsion/parser/file/FileStorageParser.java +++ b/src/main/java/net/b0at/torsion/parser/file/FileStorageParser.java @@ -4,10 +4,6 @@ import java.io.File; -/** - * Created by Jordin on 8/5/2017. - * Jordin is still best hacker. - */ public abstract class FileStorageParser implements StorageParser { private File file; diff --git a/src/main/java/net/b0at/torsion/parser/file/JSONFileParser.java b/src/main/java/net/b0at/torsion/parser/file/JSONFileParser.java index 397d3dc..b3bad98 100644 --- a/src/main/java/net/b0at/torsion/parser/file/JSONFileParser.java +++ b/src/main/java/net/b0at/torsion/parser/file/JSONFileParser.java @@ -6,11 +6,10 @@ import java.io.*; -/** - * Created by Jordin on 8/4/2017. - * Jordin is still best hacker. - */ public class JSONFileParser extends FileStorageParser { + private static boolean serializeNulls; + private static boolean lenient; + public JSONFileParser(File file) { super(file); } @@ -51,6 +50,24 @@ public void save(T object) { } private static Gson constructGsonBuilder() { - return new GsonBuilder().setPrettyPrinting().serializeNulls().create(); + GsonBuilder builder = new GsonBuilder(); + builder.setPrettyPrinting(); + if (JSONFileParser.serializeNulls) { + builder.serializeNulls(); + } + + if (JSONFileParser.lenient) { + builder.setLenient(); + } + + return builder.create(); + } + + public static void setSerializeNulls(boolean serializeNulls) { + JSONFileParser.serializeNulls = serializeNulls; + } + + public static void setLenient(boolean lenient) { + JSONFileParser.lenient = lenient; } } diff --git a/src/main/java/net/b0at/torsion/parser/file/NullFileParser.java b/src/main/java/net/b0at/torsion/parser/file/NullFileParser.java index 1b09757..3560f8d 100644 --- a/src/main/java/net/b0at/torsion/parser/file/NullFileParser.java +++ b/src/main/java/net/b0at/torsion/parser/file/NullFileParser.java @@ -2,10 +2,6 @@ import java.io.File; -/** - * Created by Jordin on 8/4/2017. - * Jordin is still best hacker. - */ public class NullFileParser extends FileStorageParser { public NullFileParser(File file) { super(file); diff --git a/src/main/java/net/b0at/torsion/parser/file/YMLFileParser.java b/src/main/java/net/b0at/torsion/parser/file/YMLFileParser.java index cc758b1..8f062f1 100644 --- a/src/main/java/net/b0at/torsion/parser/file/YMLFileParser.java +++ b/src/main/java/net/b0at/torsion/parser/file/YMLFileParser.java @@ -7,10 +7,6 @@ import java.io.*; -/** - * Created by Jordin on 8/4/2017. - * Jordin is still best hacker. - */ public class YMLFileParser extends FileStorageParser { public YMLFileParser(File file) { super(file); diff --git a/src/test/java/net/b0at/torsion/test/StorageTest.java b/src/test/java/net/b0at/torsion/test/StorageTest.java index b030641..707c46c 100644 --- a/src/test/java/net/b0at/torsion/test/StorageTest.java +++ b/src/test/java/net/b0at/torsion/test/StorageTest.java @@ -1,15 +1,10 @@ package net.b0at.torsion.test; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import com.google.gson.annotations.SerializedName; import net.b0at.torsion.FileStorage; import net.b0at.torsion.Storage; -import java.io.File; import java.io.IOException; -import java.util.List; -import java.util.Map; /** * Created by Jordin on 8/4/2017. @@ -18,12 +13,10 @@ public class StorageTest { public static void main(String[] args) throws IOException { - FileStorage.setBaseDirectory(new File("./testing/test/123/dir")); - Storage storage = FileStorage.of(TestClass.class, "fuke.invalid-extension"); - + Storage storage = FileStorage.of(TestClass.class, "test.yml"); TestClass testClass = storage.load(); - testClass.testDouble = 5; + testClass.testInt = 5; storage.save(testClass); } @@ -31,21 +24,6 @@ public static class TestClass { @SerializedName("test-int") public int testInt = -1; - @SerializedName("test-double") - public double testDouble = 251.125156; - - @SerializedName("test-string") - public String testString = ""; - - @SerializedName("test-list") - public List testList = ImmutableList.of("Testing", "Arrays", "Of", "Strings", "To", "And", "From", "Configurations"); - - @SerializedName("map-test") - public Map testMap = ImmutableMap.builder() - .put("test", 5) - .put("testing", 2) - .put("11", 11) - .build(); - + public int testInt2 = -7; } }