diff --git a/common/com/pahimar/ee3/api/CustomWrappedStackSerializer.java b/common/com/pahimar/ee3/api/CustomWrappedStackSerializer.java new file mode 100644 index 00000000..257b3111 --- /dev/null +++ b/common/com/pahimar/ee3/api/CustomWrappedStackSerializer.java @@ -0,0 +1,29 @@ +package com.pahimar.ee3.api; + +import java.lang.reflect.Type; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import com.pahimar.ee3.item.CustomWrappedStack; + +public class CustomWrappedStackSerializer implements JsonDeserializer, JsonSerializer { + + @Override + public JsonElement serialize(CustomWrappedStack customWrappedStack, Type type, JsonSerializationContext context) { + + // TODO Auto-generated method stub + return null; + } + + @Override + public CustomWrappedStack deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { + + // TODO Auto-generated method stub + return null; + } + +} diff --git a/common/com/pahimar/ee3/api/EmcValueSerializer.java b/common/com/pahimar/ee3/api/EmcValueSerializer.java new file mode 100644 index 00000000..f5082eac --- /dev/null +++ b/common/com/pahimar/ee3/api/EmcValueSerializer.java @@ -0,0 +1,30 @@ +package com.pahimar.ee3.api; + +import java.lang.reflect.Type; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import com.pahimar.ee3.emc.EmcValue; + +public class EmcValueSerializer implements JsonDeserializer, JsonSerializer { + + @Override + public JsonElement serialize(EmcValue emcValue, Type type, JsonSerializationContext context) { + + JsonObject jsonObject = new JsonObject(); + return null; + } + + @Override + public EmcValue deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { + + // TODO Auto-generated method stub + return null; + } + +} diff --git a/common/com/pahimar/ee3/emc/EmcValue.java b/common/com/pahimar/ee3/emc/EmcValue.java index 55e6bb21..d6b63a7a 100644 --- a/common/com/pahimar/ee3/emc/EmcValue.java +++ b/common/com/pahimar/ee3/emc/EmcValue.java @@ -4,6 +4,11 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonSyntaxException; +import com.pahimar.ee3.api.EmcValueSerializer; + /** * Equivalent-Exchange-3 * @@ -15,6 +20,7 @@ import java.util.List; */ public class EmcValue implements Comparable { + private static final Gson gson = (new GsonBuilder()).registerTypeAdapter(EmcValue.class, new EmcValueSerializer()).create(); public final float[] components; public EmcValue() { @@ -148,6 +154,33 @@ public class EmcValue implements Comparable { return -1; } } + + /** + * Deserializes an EmcValue object from the given serialized json String + * + * @param jsonEmcValue Json encoded String representing a EmcValue object + * @return The EmcValue that was encoded as json, or null if a valid EmcValue could not be decoded from given String + */ + public static EmcValue createFromJson(String jsonEmcValue) { + + try { + return (EmcValue) gson.fromJson(jsonEmcValue, EmcValue.class); + } + catch (JsonSyntaxException exception) { + // TODO Log something regarding the failed parse + } + + return null; + } + + /** + * Returns this EmcValue as a json serialized String + * + * @return Json serialized String of this EmcValue + */ + public String toJson() { + return gson.toJson(this); + } private static List collateComponents(List uncollatedComponents) {