Skip to content

Commit

Permalink
fix: checking if the JSON element is 'null' before trying to get the …
Browse files Browse the repository at this point in the history
…'value' property
  • Loading branch information
AllanCapistrano committed Mar 16, 2024
1 parent 3125bfe commit 03ac113
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main/java/reputation/node/models/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 03ac113

Please sign in to comment.