Better protection of parsing values from json

This commit is contained in:
Pahimar 2016-05-20 23:14:36 -04:00
parent 26d1e76fe1
commit 2b46fa82eb
2 changed files with 11 additions and 20 deletions

View file

@ -25,27 +25,22 @@ public class FluidStackSerializer implements JsonSerializer<FluidStack>, JsonDes
String name = null;
NBTTagCompound tagCompound = null;
try {
if (jsonObject.has(NAME) && jsonObject.get(NAME).getAsJsonPrimitive().isString()) {
name = jsonObject.get(NAME).getAsString();
}
}
catch (IllegalStateException exception) {
if (jsonObject.has(NAME) && jsonObject.get(NAME).isJsonPrimitive()) {
name = jsonObject.getAsJsonPrimitive(NAME).getAsString();
}
try {
if (jsonObject.has(TAG_COMPOUND) && jsonObject.get(TAG_COMPOUND).getAsJsonPrimitive().isString()) {
if (jsonObject.has(TAG_COMPOUND) && jsonObject.get(TAG_COMPOUND).isJsonPrimitive()) {
try {
NBTBase nbtBase = JsonToNBT.func_150315_a(jsonObject.get(TAG_COMPOUND).getAsString());
if (nbtBase instanceof NBTTagCompound) {
tagCompound = (NBTTagCompound) nbtBase;
}
}
catch (NBTException e) {
}
}
catch (IllegalStateException exception) {
}
catch (NBTException e) {
}
if (name != null) {
Fluid fluid = FluidRegistry.getFluid(name);

View file

@ -13,16 +13,12 @@ public class OreStackSerializer implements JsonSerializer<OreStack>, JsonDeseria
public OreStack deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
if (json.isJsonObject()) {
JsonObject jsonObject = (JsonObject) json;
try {
if (jsonObject.has(NAME) && jsonObject.get(NAME).getAsJsonPrimitive().isString()) {
String name = jsonObject.get(NAME).getAsString();
return new OreStack(name);
}
}
catch (IllegalStateException exception) {
// TODO We could probably log here that an invalid piece of data was found
if (jsonObject.has(NAME) && jsonObject.get(NAME).isJsonPrimitive()) {
String name = jsonObject.getAsJsonPrimitive(NAME).getAsString();
return new OreStack(name);
}
}