Java Code Examples for com.google.gson.JsonObject#isJsonObject()
The following examples show how to use
com.google.gson.JsonObject#isJsonObject() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeviceStatusManagerImpl.java From smarthome with Eclipse Public License 2.0 | 6 votes |
private List<Device> getDetailedDevices() { List<Device> deviceList = new LinkedList<Device>(); JsonObject result = connMan.getDigitalSTROMAPI().query2(connMan.getSessionToken(), GET_DETAILD_DEVICES); if (result != null && result.isJsonObject()) { if (result.getAsJsonObject().get(GeneralLibConstance.QUERY_BROADCAST_ZONE_STRING).isJsonObject()) { result = result.getAsJsonObject().get(GeneralLibConstance.QUERY_BROADCAST_ZONE_STRING) .getAsJsonObject(); for (Entry<String, JsonElement> entry : result.entrySet()) { if (!(entry.getKey().equals(JSONApiResponseKeysEnum.ZONE_ID.getKey()) && entry.getKey().equals(JSONApiResponseKeysEnum.NAME.getKey())) && entry.getValue().isJsonObject()) { deviceList.add(new DeviceImpl(entry.getValue().getAsJsonObject())); } } } } return deviceList; }
Example 2
Source File: WeatherResponseUtil.java From benten with MIT License | 5 votes |
private static void formatMessage(SlackFormatter responseToSend, JsonObject object, String checker, String key, String messageFormat, boolean elseMessage) { JsonObject checkerObject = object.getAsJsonObject(checker); if (checkerObject != null && checkerObject.isJsonObject() && checkerObject.has(key)) { String value = checkerObject.getAsJsonPrimitive(key).getAsString(); responseToSend.bold(String.format(messageFormat, value)); responseToSend.newline(); } else if(elseMessage){ responseToSend.bold("No " + checker); responseToSend.newline(); } }
Example 3
Source File: Module.java From ha-bridge with Apache License 2.0 | 5 votes |
public boolean isModuleValid(JsonObject theExtensions) { ModuleTypes moduleTypes = null; if (this.name == null || this.name.trim().isEmpty()) return false; if (isSwitch()) return true; if (isDimmer()) return true; if (isLight()) return true; if (theExtensions != null && theExtensions.isJsonObject() && theExtensions.get("moduleTypes").isJsonArray()) { try { moduleTypes = new Gson().fromJson(theExtensions, ModuleTypes.class); } catch (Exception e) { log.warn("Could not parse extensions for {} with {}", this.name, theExtensions); return false; } if (moduleTypes == null) return false; for (ModuleType moduleType : moduleTypes.getModuleTypes()) { if (isDeviceType(moduleType.getModuleType())) return true; } } return false; }
Example 4
Source File: DeviceStatusManagerImpl.java From smarthome with Eclipse Public License 2.0 | 5 votes |
private void setInizialStateWithLastCallScenes() { if (sceneMan == null) { return; } JsonObject response = connMan.getDigitalSTROMAPI().query2(connMan.getSessionToken(), LAST_CALL_SCENE_QUERY); if (!response.isJsonObject()) { return; } for (Entry<String, JsonElement> entry : response.entrySet()) { if (!entry.getValue().isJsonObject()) { continue; } JsonObject zone = entry.getValue().getAsJsonObject(); int zoneID = -1; short groupID = -1; short sceneID = -1; if (zone.get(JSONApiResponseKeysEnum.ZONE_ID.getKey()) != null) { zoneID = zone.get(JSONApiResponseKeysEnum.ZONE_ID.getKey()).getAsInt(); } for (Entry<String, JsonElement> groupEntry : zone.entrySet()) { if (groupEntry.getKey().startsWith("group") && groupEntry.getValue().isJsonObject()) { JsonObject group = groupEntry.getValue().getAsJsonObject(); if (group.get(JSONApiResponseKeysEnum.DEVICES.getKey()) != null) { if (group.get(JSONApiResponseKeysEnum.GROUP.getKey()) != null) { groupID = group.get(JSONApiResponseKeysEnum.GROUP.getKey()).getAsShort(); } if (group.get(JSONApiResponseKeysEnum.LAST_CALL_SCENE.getKey()) != null) { sceneID = group.get(JSONApiResponseKeysEnum.LAST_CALL_SCENE.getKey()).getAsShort(); } if (zoneID > -1 && groupID > -1 && sceneID > -1) { logger.debug("initial state, call scene {}-{}-{}", zoneID, groupID, sceneID); sceneMan.callInternalSceneWithoutDiscovery(zoneID, groupID, sceneID); } } } } } }
Example 5
Source File: JsonHandler.java From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static JsonElement getJsonElement(JsonObject jObject, String key) throws ParsingException { if (jObject == null || key == null) { throw new ParsingException("Wrong params"); } if (jObject.isJsonObject() && jObject.has(key)) { return jObject.get(key); } else { throw new ParsingException("The given jObject is not JsonObject, or doesn't contain given key"); } }