use of com.massivecraft.massivecore.xlib.gson.JsonNull in project MassiveCore by MassiveCraft.
the class AdapterMassiveX method deserialize.
@Override
public T deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
ParameterizedType ptype = (ParameterizedType) type;
/*// TODO: Temporary Debug
if (MUtil.getStackTraceString().contains("com.massivecraft.factions.entity.FactionColl.init"))
{
typeDebug(ptype);
typeDebug(getSuperType(ptype));
typeDebug(getSuperType(getSuperType(ptype)));
}*/
// Calculate def
Class<?> clazz = getClazz(ptype);
boolean def = Def.class.isAssignableFrom(clazz);
// If this is a Def ...
if (def) {
// ... then deserialize it as if it were the regular Java collection!
// SUPER TYPE x2 EXAMPLE: MassiveListDef --> MassiveList --> ArrayList
Object parent = context.deserialize(json, getSuperType(getSuperType(ptype)));
return create(parent, def, json, type, context);
} else // If this a regular Massive structure and not a Def ...
{
// ... and the json is null or a JsonNull ...
if (json == null || json instanceof JsonNull) {
// ... then deserialize as a null!
return null;
} else // ... and it's non null and contains something ...
{
// ... then deserialize it as if it were the regular java collection!
// SUPER TYPE x1 EXAMPLE: MassiveList --> ArrayList
Object parent = context.deserialize(json, getSuperType(ptype));
return create(parent, def, json, type, context);
}
}
}
use of com.massivecraft.massivecore.xlib.gson.JsonNull 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);
}
Aggregations