Search in sources :

Example 11 with JsonElement

use of com.massivecraft.massivecore.xlib.gson.JsonElement in project MassiveCore by MassiveCraft.

the class GsonMongoConverter method gson2MongoArray.

public static BasicDBList gson2MongoArray(JsonElement inElement) {
    JsonArray in = inElement.getAsJsonArray();
    BasicDBList out = new BasicDBList();
    for (int i = 0; i < in.size(); i++) {
        JsonElement element = in.get(i);
        if (element.isJsonArray()) {
            out.add(gson2MongoArray(element));
        } else if (element.isJsonObject()) {
            out.add(gson2MongoObject(element));
        } else {
            out.add(gson2MongoPrimitive(element));
        }
    }
    return out;
}
Also used : JsonArray(com.massivecraft.massivecore.xlib.gson.JsonArray) BasicDBList(com.massivecraft.massivecore.xlib.mongodb.BasicDBList) JsonElement(com.massivecraft.massivecore.xlib.gson.JsonElement)

Example 12 with JsonElement

use of com.massivecraft.massivecore.xlib.gson.JsonElement in project MassiveCore by MassiveCraft.

the class GsonMongoConverter method gson2MongoObject.

public static BasicDBObject gson2MongoObject(JsonElement inElement, BasicDBObject out) {
    JsonObject in = inElement.getAsJsonObject();
    for (Entry<String, JsonElement> entry : in.entrySet()) {
        String key = gson2MongoKey(entry.getKey());
        JsonElement val = entry.getValue();
        if (val.isJsonArray()) {
            out.put(key, gson2MongoArray(val));
        } else if (val.isJsonObject()) {
            out.put(key, gson2MongoObject(val));
        } else {
            out.put(key, gson2MongoPrimitive(val));
        }
    }
    return out;
}
Also used : JsonElement(com.massivecraft.massivecore.xlib.gson.JsonElement) JsonObject(com.massivecraft.massivecore.xlib.gson.JsonObject)

Example 13 with JsonElement

use of com.massivecraft.massivecore.xlib.gson.JsonElement in project MassiveCore by MassiveCraft.

the class AdapterEntry method deserialize.

@Override
public Entry<?, ?> deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
    // NULL
    if (json == null)
        return null;
    if (json instanceof JsonNull)
        return null;
    JsonArray jsonArray = (JsonArray) json;
    JsonElement keyJson = jsonArray.get(0);
    JsonElement valueJson = jsonArray.get(1);
    Type keyType = getKeyType(type);
    Type valueType = getValueType(type);
    Object key = context.deserialize(keyJson, keyType);
    Object value = context.deserialize(valueJson, valueType);
    return new SimpleEntry<>(key, value);
}
Also used : JsonArray(com.massivecraft.massivecore.xlib.gson.JsonArray) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) JsonElement(com.massivecraft.massivecore.xlib.gson.JsonElement) SimpleEntry(java.util.AbstractMap.SimpleEntry) JsonNull(com.massivecraft.massivecore.xlib.gson.JsonNull)

Example 14 with JsonElement

use of com.massivecraft.massivecore.xlib.gson.JsonElement in project MassiveCore by MassiveCraft.

the class AdapterInventory method getItemStack.

private static ItemStack getItemStack(JsonObject jsonInventory, String idx) {
    // Get jsonItemStack
    JsonElement jsonItemStack = jsonInventory.get(idx);
    if (jsonItemStack == null)
        return null;
    ItemStack ret = MassiveCore.gson.fromJson(jsonItemStack, ItemStack.class);
    return ret;
}
Also used : JsonElement(com.massivecraft.massivecore.xlib.gson.JsonElement) DataItemStack(com.massivecraft.massivecore.item.DataItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Example 15 with JsonElement

use of com.massivecraft.massivecore.xlib.gson.JsonElement in project MassiveCore by MassiveCraft.

the class MigratorInventory001StringId method updateField.

public void updateField(JsonObject json, String name) {
    JsonElement element = json.get(name);
    if (element == null)
        return;
    if (!element.isJsonObject())
        return;
    JsonObject object = element.getAsJsonObject();
    MigratorUtil.migrate(DataItemStack.class, object);
}
Also used : JsonElement(com.massivecraft.massivecore.xlib.gson.JsonElement) JsonObject(com.massivecraft.massivecore.xlib.gson.JsonObject)

Aggregations

JsonElement (com.massivecraft.massivecore.xlib.gson.JsonElement)17 JsonObject (com.massivecraft.massivecore.xlib.gson.JsonObject)9 JsonArray (com.massivecraft.massivecore.xlib.gson.JsonArray)4 ParameterizedType (java.lang.reflect.ParameterizedType)4 Type (java.lang.reflect.Type)4 DataItemStack (com.massivecraft.massivecore.item.DataItemStack)3 ItemStack (org.bukkit.inventory.ItemStack)3 JsonPrimitive (com.massivecraft.massivecore.xlib.gson.JsonPrimitive)2 PlayerInventory (org.bukkit.inventory.PlayerInventory)2 MassiveList (com.massivecraft.massivecore.collections.MassiveList)1 MassiveListDef (com.massivecraft.massivecore.collections.MassiveListDef)1 MassiveMap (com.massivecraft.massivecore.collections.MassiveMap)1 DataBannerPattern (com.massivecraft.massivecore.item.DataBannerPattern)1 MixinInventory (com.massivecraft.massivecore.mixin.MixinInventory)1 JsonNull (com.massivecraft.massivecore.xlib.gson.JsonNull)1 BasicDBList (com.massivecraft.massivecore.xlib.mongodb.BasicDBList)1 Field (java.lang.reflect.Field)1 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1