Better NPE protection in serializing energy value maps
This commit is contained in:
parent
43860832ff
commit
8d40883473
1 changed files with 4 additions and 2 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue