use of com.massivecraft.massivecore.xlib.mongodb.DBObject 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;
}
use of com.massivecraft.massivecore.xlib.mongodb.DBObject 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;
}
Aggregations