Search in sources :

Example 21 with JsonObject

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

the class GsonMongoConverter method mongo2GsonObject.

public static JsonObject mongo2GsonObject(DBObject inObject) {
    if (!(inObject instanceof BasicDBObject))
        throw new IllegalArgumentException("Expected BasicDBObject as argument type!");
    BasicDBObject in = (BasicDBObject) inObject;
    JsonObject jsonObject = new JsonObject();
    for (Entry<String, Object> entry : in.entrySet()) {
        String key = mongo2GsonKey(entry.getKey());
        Object val = entry.getValue();
        if (val instanceof BasicDBList) {
            jsonObject.add(key, mongo2GsonArray((BasicDBList) val));
        } else if (val instanceof BasicDBObject) {
            jsonObject.add(key, mongo2GsonObject((BasicDBObject) val));
        } else {
            jsonObject.add(key, mongo2GsonPrimitive(val));
        }
    }
    return jsonObject;
}
Also used : BasicDBObject(com.massivecraft.massivecore.xlib.mongodb.BasicDBObject) BasicDBList(com.massivecraft.massivecore.xlib.mongodb.BasicDBList) JsonObject(com.massivecraft.massivecore.xlib.gson.JsonObject) JsonObject(com.massivecraft.massivecore.xlib.gson.JsonObject) DBObject(com.massivecraft.massivecore.xlib.mongodb.DBObject) BasicDBObject(com.massivecraft.massivecore.xlib.mongodb.BasicDBObject)

Aggregations

JsonObject (com.massivecraft.massivecore.xlib.gson.JsonObject)21 JsonElement (com.massivecraft.massivecore.xlib.gson.JsonElement)9 SimpleEntry (java.util.AbstractMap.SimpleEntry)4 BasicDBObject (com.massivecraft.massivecore.xlib.mongodb.BasicDBObject)3 Entry (java.util.Map.Entry)3 DataItemStack (com.massivecraft.massivecore.item.DataItemStack)2 JsonPrimitive (com.massivecraft.massivecore.xlib.gson.JsonPrimitive)2 JsonSyntaxException (com.massivecraft.massivecore.xlib.gson.JsonSyntaxException)2 ItemStack (org.bukkit.inventory.ItemStack)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 TypeString (com.massivecraft.massivecore.command.type.primitive.TypeString)1 DataBannerPattern (com.massivecraft.massivecore.item.DataBannerPattern)1 MixinInventory (com.massivecraft.massivecore.mixin.MixinInventory)1 Coll (com.massivecraft.massivecore.store.Coll)1 Db (com.massivecraft.massivecore.store.Db)1 SenderColl (com.massivecraft.massivecore.store.SenderColl)1 JsonArray (com.massivecraft.massivecore.xlib.gson.JsonArray)1