From 03ac1132c5eb57021601d3f92650ed27044573f3 Mon Sep 17 00:00:00 2001 From: AllanCapistrano Date: Sat, 16 Mar 2024 15:17:12 -0300 Subject: [PATCH] fix: checking if the JSON element is 'null' before trying to get the 'value' property --- src/main/java/reputation/node/models/Node.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/reputation/node/models/Node.java b/src/main/java/reputation/node/models/Node.java index 0e5e946..2a8c373 100644 --- a/src/main/java/reputation/node/models/Node.java +++ b/src/main/java/reputation/node/models/Node.java @@ -3,6 +3,8 @@ import br.uefs.larsid.extended.mapping.devices.services.IDevicePropertiesManager; import br.ufba.dcc.wiser.soft_iot.entities.Device; import br.ufba.dcc.wiser.soft_iot.entities.Sensor; + +import com.google.gson.JsonElement; import com.google.gson.JsonObject; import dlt.client.tangle.hornet.enums.TransactionType; import dlt.client.tangle.hornet.model.DeviceSensorId; @@ -543,6 +545,7 @@ private void requestAndEvaluateNodeService( boolean isNullable = false; String response = null; String sensorValue = null; + JsonElement valueJsonElement = null; int serviceEvaluation = 0; float nodeCredibility = 0; @@ -587,7 +590,11 @@ private void requestAndEvaluateNodeService( JsonObject jsonObject = JsonStringToJsonObject.convert(response); - sensorValue = jsonObject.get("value").getAsString(); + valueJsonElement = jsonObject.get("value"); + + if (valueJsonElement != null) { + sensorValue = valueJsonElement.getAsString(); + } } catch (MalformedURLException mue) { logger.severe(mue.getMessage()); } catch (IOException ioe) {