Search in sources :

Example 1 with BasicDBList

use of com.massivecraft.massivecore.xlib.mongodb.BasicDBList 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 2 with BasicDBList

use of com.massivecraft.massivecore.xlib.mongodb.BasicDBList 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)

Example 3 with BasicDBList

use of com.massivecraft.massivecore.xlib.mongodb.BasicDBList in project MassiveCore by MassiveCraft.

the class GsonMongoConverter method mongo2GsonArray.

public static JsonArray mongo2GsonArray(DBObject inObject) {
    if (!(inObject instanceof BasicDBList))
        throw new IllegalArgumentException("Expected BasicDBList as argument type!");
    BasicDBList in = (BasicDBList) inObject;
    JsonArray jsonArray = new JsonArray();
    for (int i = 0; i < in.size(); i++) {
        Object object = in.get(i);
        if (object instanceof BasicDBList) {
            jsonArray.add(mongo2GsonArray((BasicDBList) object));
        } else if (object instanceof BasicDBObject) {
            jsonArray.add(mongo2GsonObject((BasicDBObject) object));
        } else {
            jsonArray.add(mongo2GsonPrimitive(object));
        }
    }
    return jsonArray;
}
Also used : JsonArray(com.massivecraft.massivecore.xlib.gson.JsonArray) BasicDBList(com.massivecraft.massivecore.xlib.mongodb.BasicDBList) BasicDBObject(com.massivecraft.massivecore.xlib.mongodb.BasicDBObject) JsonObject(com.massivecraft.massivecore.xlib.gson.JsonObject) DBObject(com.massivecraft.massivecore.xlib.mongodb.DBObject) BasicDBObject(com.massivecraft.massivecore.xlib.mongodb.BasicDBObject)

Aggregations

BasicDBList (com.massivecraft.massivecore.xlib.mongodb.BasicDBList)3 JsonArray (com.massivecraft.massivecore.xlib.gson.JsonArray)2 JsonObject (com.massivecraft.massivecore.xlib.gson.JsonObject)2 BasicDBObject (com.massivecraft.massivecore.xlib.mongodb.BasicDBObject)2 DBObject (com.massivecraft.massivecore.xlib.mongodb.DBObject)2 JsonElement (com.massivecraft.massivecore.xlib.gson.JsonElement)1