SnippetDefinintion now delegates to JsonHandler instead of an own Gson
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Sat, 2 May 2020 12:18:23 +0000 (14:18 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Sat, 2 May 2020 12:18:23 +0000 (14:18 +0200)
plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/SnippetDefinintion.java
plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/util/JsonHandler.java

index c5fecf2..94c7e4e 100644 (file)
@@ -2,9 +2,10 @@ package net.mograsim.logic.model.snippets;
 
 import java.util.function.BiFunction;
 
-import com.google.gson.Gson;
 import com.google.gson.JsonElement;
 
+import net.mograsim.logic.model.util.JsonHandler;
+
 public interface SnippetDefinintion<C, P, S>
 {
        public Class<P> getParamClass();
@@ -20,7 +21,7 @@ public interface SnippetDefinintion<C, P, S>
                                throw new IllegalArgumentException("Params given where none were expected");
                        return create(context, (P) null);
                }
-               return create(context, new Gson().fromJson(params, getParamClass()));
+               return create(context, JsonHandler.fromJson(params, getParamClass()));
        }
 
        public static <C, P, S> SnippetDefinintion<C, P, S> create(Class<P> paramClass, BiFunction<C, P, S> supplier)
index 7c8e353..4c49104 100644 (file)
@@ -45,6 +45,11 @@ public class JsonHandler
                return parser.fromJson(src, type);
        }
 
+       public static <T> T fromJson(JsonElement json, Class<T> type)
+       {
+               return parser.fromJson(json, type);
+       }
+
        public static <T> T fromJsonTree(JsonElement src, Class<T> type)
        {
                return parser.fromJson(src, type);