I have the following code:
JsonElement deviceConfig = null;
JsonObject status = getRestAPI().Connectivity().getDeviceStatus(device);
deviceConfig = status.get("deviceConfig");
if (deviceConfig == null || deviceConfig.isJsonNull()) {
deviceConfig = status.get("mConfig");
}
if (deviceConfig != null && !deviceConfig.isJsonNull()) {
if (!deviceConfig.getAsString().isEmpty()) {
break;
}
}
For some reasons, I get the following error:
java.lang.UnsupportedOperationException: JsonObject at com.google.gson.JsonElement.getAsString(JsonElement.java:191)
In this line:
if (!deviceConfig.getAsString().isEmpty()) {
Any idea why I get this exception although I checked that the JSON is not null?
JsonElementdeviceConfig.getAsJsonObject.toString()to fix this issue?