Better protection of parsing values from json
This commit is contained in:
parent
bd4b5bf5ee
commit
26d1e76fe1
2 changed files with 17 additions and 24 deletions
|
@ -42,7 +42,7 @@ public class EnergyValueMapSerializer implements JsonSerializer<Map<WrappedStack
|
||||||
if (jsonValueMapping.get(ENERGY_VALUE).isJsonPrimitive()) {
|
if (jsonValueMapping.get(ENERGY_VALUE).isJsonPrimitive()) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
energyValue = new EnergyValue(((JsonPrimitive) jsonValueMapping.get(ENERGY_VALUE)).getAsNumber());
|
energyValue = new EnergyValue(jsonValueMapping.getAsJsonPrimitive(ENERGY_VALUE).getAsNumber());
|
||||||
}
|
}
|
||||||
catch (NumberFormatException e) {
|
catch (NumberFormatException e) {
|
||||||
// TODO Logging
|
// TODO Logging
|
||||||
|
|
|
@ -26,37 +26,30 @@ public class ItemStackSerializer implements JsonSerializer<ItemStack>, JsonDeser
|
||||||
int metaValue = 0;
|
int metaValue = 0;
|
||||||
NBTTagCompound tagCompound = null;
|
NBTTagCompound tagCompound = null;
|
||||||
|
|
||||||
try {
|
if (jsonObject.has(NAME) && jsonObject.get(NAME).isJsonPrimitive()) {
|
||||||
if (jsonObject.has(NAME) && jsonObject.get(NAME).getAsJsonPrimitive().isString()) {
|
name = jsonObject.getAsJsonPrimitive(NAME).getAsString();
|
||||||
name = jsonObject.get(NAME).getAsString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IllegalStateException exception) {
|
|
||||||
// TODO We could probably log here that an invalid piece of data was found
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (jsonObject.has(META_VALUE) && jsonObject.get(META_VALUE).isJsonPrimitive()) {
|
||||||
try {
|
try {
|
||||||
if (jsonObject.has(META_VALUE) && jsonObject.get(META_VALUE).getAsJsonPrimitive().isNumber()) {
|
metaValue = jsonObject.getAsJsonPrimitive(META_VALUE).getAsInt();
|
||||||
metaValue = jsonObject.get(META_VALUE).getAsInt();
|
|
||||||
}
|
}
|
||||||
|
catch (NumberFormatException e) {
|
||||||
|
// TODO Logging
|
||||||
}
|
}
|
||||||
catch (IllegalStateException exception) {
|
|
||||||
// TODO We could probably log here that an invalid piece of data was found
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if (jsonObject.has(TAG_COMPOUND) && jsonObject.get(TAG_COMPOUND).isJsonPrimitive()) {
|
||||||
if (jsonObject.has(TAG_COMPOUND) && jsonObject.get(TAG_COMPOUND).getAsJsonPrimitive().isString()) {
|
|
||||||
|
|
||||||
NBTBase nbtBase = JsonToNBT.func_150315_a(jsonObject.get(TAG_COMPOUND).getAsString());
|
try {
|
||||||
|
NBTBase nbtBase = JsonToNBT.func_150315_a(jsonObject.getAsJsonPrimitive(TAG_COMPOUND).getAsString());
|
||||||
if (nbtBase instanceof NBTTagCompound) {
|
if (nbtBase instanceof NBTTagCompound) {
|
||||||
tagCompound = (NBTTagCompound) nbtBase;
|
tagCompound = (NBTTagCompound) nbtBase;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (NBTException e) {
|
catch (NBTException e) {
|
||||||
|
// TODO Logging
|
||||||
}
|
}
|
||||||
catch (IllegalStateException exception) {
|
|
||||||
// TODO We could probably log here that an invalid piece of data was found
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
|
|
Loading…
Reference in a new issue