We wanna serialize JsonElements as JsonElements, duh
This commit is contained in:
parent
5782eb9193
commit
f4b3924dc3
@ -14,6 +14,7 @@ import org.bukkit.inventory.PlayerInventory;
|
|||||||
|
|
||||||
import com.massivecraft.mcore.adapter.InventoryAdapter;
|
import com.massivecraft.mcore.adapter.InventoryAdapter;
|
||||||
import com.massivecraft.mcore.adapter.ItemStackAdapter;
|
import com.massivecraft.mcore.adapter.ItemStackAdapter;
|
||||||
|
import com.massivecraft.mcore.adapter.JsonElementAdapter;
|
||||||
import com.massivecraft.mcore.adapter.ObjectIdAdapter;
|
import com.massivecraft.mcore.adapter.ObjectIdAdapter;
|
||||||
import com.massivecraft.mcore.adapter.PlayerInventoryAdapter;
|
import com.massivecraft.mcore.adapter.PlayerInventoryAdapter;
|
||||||
import com.massivecraft.mcore.adapter.UUIDAdapter;
|
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.bson.types.ObjectId;
|
||||||
import com.massivecraft.mcore.xlib.gson.Gson;
|
import com.massivecraft.mcore.xlib.gson.Gson;
|
||||||
import com.massivecraft.mcore.xlib.gson.GsonBuilder;
|
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
|
public class MCore extends MPlugin
|
||||||
{
|
{
|
||||||
@ -66,6 +71,10 @@ public class MCore extends MPlugin
|
|||||||
.setPrettyPrinting()
|
.setPrettyPrinting()
|
||||||
.disableHtmlEscaping()
|
.disableHtmlEscaping()
|
||||||
.excludeFieldsWithModifiers(Modifier.TRANSIENT)
|
.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(ObjectId.class, ObjectIdAdapter.get())
|
||||||
.registerTypeAdapter(UUID.class, UUIDAdapter.get())
|
.registerTypeAdapter(UUID.class, UUIDAdapter.get())
|
||||||
.registerTypeAdapter(ItemStack.class, ItemStackAdapter.get())
|
.registerTypeAdapter(ItemStack.class, ItemStackAdapter.get())
|
||||||
|
37
src/com/massivecraft/mcore/adapter/JsonElementAdapter.java
Normal file
37
src/com/massivecraft/mcore/adapter/JsonElementAdapter.java
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user