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;
}
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;
}
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);
}
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;
}
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);
}
Aggregations