You need to know the class of the field Gson (String, Boolean, Integer ...) In order to compare it further using instanceof.
gson.get("key").getClass() Returns com.google.gson.JsonPrimitive. But how does this primitive compare with the classes of java itself?