use of com.google.gson.JsonParseException in project rom-manager by Jakz.
the class JsonPluginAdapter method deserialize.
@SuppressWarnings("unchecked")
@Override
public T deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
String name = json.getAsJsonObject().get("class").getAsString();
try {
Class<?> clazz = Class.forName(name);
T instance = (T) clazz.newInstance();
instance.unserialize(json, context);
return instance;
} catch (ClassNotFoundException e) {
throw new JsonParseException(e);
} catch (IllegalAccessException | InstantiationException e) {
e.printStackTrace();
}
return null;
}
use of com.google.gson.JsonParseException in project tutorials by eugenp.
the class ActorGsonDeserializer method deserialize.
@Override
public ActorGson deserialize(JsonElement json, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
final JsonObject jsonObject = json.getAsJsonObject();
final JsonElement jsonImdbId = jsonObject.get("imdbId");
final JsonElement jsonDateOfBirth = jsonObject.get("dateOfBirth");
final JsonArray jsonFilmography = jsonObject.getAsJsonArray("filmography");
final ArrayList<String> filmList = new ArrayList<String>();
if (jsonFilmography != null) {
for (int i = 0; i < jsonFilmography.size(); i++) {
filmList.add(jsonFilmography.get(i).getAsString());
}
}
ActorGson actorGson = null;
try {
actorGson = new ActorGson(jsonImdbId.getAsString(), sdf.parse(jsonDateOfBirth.getAsString()), filmList);
} catch (final ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return actorGson;
}
use of com.google.gson.JsonParseException in project Binnie by ForestryMC.
the class StyleSheetParser method parseArea.
private static Area parseArea(JsonArray uvArray) {
int[] ints = new int[uvArray.size()];
if (ints.length < 1 || ints.length > 4) {
throw new JsonParseException("Parameter must have between one and four numbers");
}
for (int i = 0; i < uvArray.size(); i++) {
JsonElement object = uvArray.get(i);
ints[i] = JsonUtils.getInt(object, "uv" + i);
}
if (ints.length == 1) {
return new Area(ints[0]);
}
if (ints.length == 2) {
return new Area(ints[0], ints[1]);
}
if (ints.length == 3) {
return new Area(ints[0], ints[1], ints[2]);
}
return new Area(ints[0], ints[1], ints[2], ints[3]);
}
use of com.google.gson.JsonParseException in project Binnie by ForestryMC.
the class StyleSheetParser method parseBorder.
private static Border parseBorder(JsonArray array) {
int[] ints = new int[array.size()];
if (ints.length < 1 || ints.length > 4) {
throw new JsonParseException("Parameter must have between one and four numbers");
}
for (int i = 0; i < array.size(); i++) {
JsonElement object = array.get(i);
ints[i] = JsonUtils.getInt(object, UV_KEY + i);
}
if (ints.length == 1) {
return new Border(ints[0]);
}
if (ints.length == 2) {
return new Border(ints[0], ints[1]);
}
if (ints.length == 3) {
return new Border(ints[0], ints[1], ints[2]);
}
return new Border(ints[0], ints[1], ints[2], ints[3]);
}
use of com.google.gson.JsonParseException in project motech by motech.
the class ImportManifestReader method readManifest.
public ImportManifest readManifest() throws IOException {
ImportManifest manifest = new ImportManifest();
jsonReader.beginArray();
while (jsonReader.hasNext()) {
jsonReader.beginObject();
String entityName = objectReader.readString("entity");
EntityDefinitionType entityType = objectReader.readEnum("type", EntityDefinitionType.class);
Entity existingEntity = getExistingEntity(entityName);
boolean canImport = isImportable(existingEntity, entityType);
String moduleName = null != existingEntity && existingEntity.isDDE() ? existingEntity.getModule() : "MDS";
ImportManifest.Record manifestRecord = manifest.addRecord(entityName, moduleName);
objectReader.expectAndSkip("schema");
manifestRecord.setCanIncludeSchema(canImport);
if (jsonReader.hasNext()) {
objectReader.expectAndSkip("instances");
manifestRecord.setCanIncludeData(canImport);
}
if (jsonReader.hasNext()) {
throw new JsonParseException("Invalid json format! Unexpected property: " + jsonReader.nextName());
}
jsonReader.endObject();
}
jsonReader.endArray();
return manifest;
}
Aggregations