We wanna serialize JsonElements as JsonElements, duh

This commit is contained in:
Olof Larsson 2013-09-10 02:40:57 +02:00
parent 5782eb9193
commit f4b3924dc3
2 changed files with 46 additions and 0 deletions

View File

@ -14,6 +14,7 @@ import org.bukkit.inventory.PlayerInventory;
import com.massivecraft.mcore.adapter.InventoryAdapter;
import com.massivecraft.mcore.adapter.ItemStackAdapter;
import com.massivecraft.mcore.adapter.JsonElementAdapter;
import com.massivecraft.mcore.adapter.ObjectIdAdapter;
import com.massivecraft.mcore.adapter.PlayerInventoryAdapter;
import com.massivecraft.mcore.adapter.UUIDAdapter;
@ -35,6 +36,10 @@ import com.massivecraft.mcore.util.TimeUnit;
import com.massivecraft.mcore.xlib.bson.types.ObjectId;
import com.massivecraft.mcore.xlib.gson.Gson;
import com.massivecraft.mcore.xlib.gson.GsonBuilder;
import com.massivecraft.mcore.xlib.gson.JsonArray;
import com.massivecraft.mcore.xlib.gson.JsonNull;
import com.massivecraft.mcore.xlib.gson.JsonObject;
import com.massivecraft.mcore.xlib.gson.JsonPrimitive;
public class MCore extends MPlugin
{
@ -66,6 +71,10 @@ public class MCore extends MPlugin
.setPrettyPrinting()
.disableHtmlEscaping()
.excludeFieldsWithModifiers(Modifier.TRANSIENT)
.registerTypeAdapter(JsonNull.class, JsonElementAdapter.get())
.registerTypeAdapter(JsonPrimitive.class, JsonElementAdapter.get())
.registerTypeAdapter(JsonArray.class, JsonElementAdapter.get())
.registerTypeAdapter(JsonObject.class, JsonElementAdapter.get())
.registerTypeAdapter(ObjectId.class, ObjectIdAdapter.get())
.registerTypeAdapter(UUID.class, UUIDAdapter.get())
.registerTypeAdapter(ItemStack.class, ItemStackAdapter.get())

View File

@ -0,0 +1,37 @@
package com.massivecraft.mcore.adapter;
import java.lang.reflect.Type;
import com.massivecraft.mcore.xlib.gson.JsonDeserializationContext;
import com.massivecraft.mcore.xlib.gson.JsonDeserializer;
import com.massivecraft.mcore.xlib.gson.JsonElement;
import com.massivecraft.mcore.xlib.gson.JsonParseException;
import com.massivecraft.mcore.xlib.gson.JsonSerializationContext;
import com.massivecraft.mcore.xlib.gson.JsonSerializer;
public class JsonElementAdapter implements JsonDeserializer<JsonElement>, JsonSerializer<JsonElement>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static JsonElementAdapter i = new JsonElementAdapter();
public static JsonElementAdapter get() { return i; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public JsonElement serialize(JsonElement src, Type typeOfSrc, JsonSerializationContext context)
{
return src;
}
@Override
public JsonElement deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
{
return json;
}
}