Better NPE protection in serializing energy value maps

This commit is contained in:
Pahimar 2016-05-19 20:03:29 -04:00
parent 43860832ff
commit 8d40883473

View file

@ -65,12 +65,14 @@ public class EnergyValueMapSerializer implements JsonSerializer<Map<WrappedStack
JsonArray jsonArray = new JsonArray();
if (src != null) {
for (WrappedStack wrappedStack : src.keySet()) {
src.keySet().stream()
.filter(wrappedStack -> wrappedStack != null && wrappedStack.getWrappedObject() != null & src.get(wrappedStack) != null)
.forEach(wrappedStack -> {
JsonObject jsonMapping = new JsonObject();
jsonMapping.add(wrappedStack.getWrappedObject().getClass().getSimpleName().toLowerCase(), context.serialize(wrappedStack.getWrappedObject()));
jsonMapping.addProperty(ENERGY_VALUE, src.get(wrappedStack).getValue());
jsonArray.add(jsonMapping);
}
});
}
return jsonArray;