I'm trying to make an API backward-compatible by checking a value.
I have to determine if one of the parameters is a string or a JsonObject.
This is what I tried:
if (oDevices.get(i).getAsJsonPrimitive().isJsonObject()) {
deviceToClean.addProperty("deviceId", oDevices.get(i).getAsJsonObject().get("name").getAsString());
} else if(oDevices.get(i).getAsJsonPrimitive().isString()) {
deviceToClean.addProperty("deviceId", oDevices.get(i).getAsString());
}
When I send a JsonObject to the API, I get the following error:
This is not a JSON Primitive.
How I can check whether oDevices.get(i) is a json object or a string?