use of com.massivecraft.massivecore.xlib.gson.JsonParseException in project MassiveCore by MassiveCraft.
the class AdapterPolymorphic method deserialize.
@Override
public T deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
if (!json.isJsonObject()) {
throw new JsonParseException("A polymorph must be an object.");
}
JsonObject jsonObject = json.getAsJsonObject();
if (!jsonObject.has(TYPE)) {
throw new JsonParseException("A polymorph must be have a \"" + TYPE + "\" field.");
}
if (!jsonObject.has(VALUE)) {
throw new JsonParseException("A polymorph must be have a \"+VALUE+\" field.");
}
String type = ((JsonPrimitive) jsonObject.get(TYPE)).getAsString();
Class<?> typeClass = null;
try {
typeClass = Class.forName(type);
} catch (ClassNotFoundException e) {
e.printStackTrace();
throw new JsonParseException(e.getMessage());
}
return context.deserialize(jsonObject.get(VALUE), typeClass);
}
Aggregations