List of usage examples for com.google.gson JsonElement isJsonNull
public boolean isJsonNull()
From source file:com.skysql.manager.api.ChartProperties.java
License:Open Source License
public ChartProperties deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { ChartProperties chartProperties = new ChartProperties(); JsonElement jsonElement = json.getAsJsonObject().get("chartProperties"); if (jsonElement != null && !jsonElement.isJsonNull()) { LinkedHashMap<String, ArrayList<ChartMappings>> chartsMap = new LinkedHashMap<String, ArrayList<ChartMappings>>(); chartProperties.setChartsMap(chartsMap); JsonArray array = jsonElement.getAsJsonArray(); for (int i = 0; i < array.size(); i++) { JsonObject jsonObject = array.get(i).getAsJsonObject(); String systemType = (jsonElement = jsonObject.get("systemtype")).isJsonNull() ? null : jsonElement.getAsString(); JsonArray mappingJson = jsonObject.get("mappings").getAsJsonArray(); int length = mappingJson.size(); ArrayList<ChartMappings> chartsList = new ArrayList<ChartMappings>(length); for (int j = 0; j < length; j++) { JsonObject mappingObject = mappingJson.get(j).getAsJsonObject(); JsonElement element;//from www .j ava 2 s . c om String name = (element = mappingObject.get("name")).isJsonNull() ? null : element.getAsString(); String description = (element = mappingObject.get("description")).isJsonNull() ? null : element.getAsString(); String unit = (element = mappingObject.get("unit")).isJsonNull() ? null : element.getAsString(); String type = (element = mappingObject.get("type")).isJsonNull() ? null : element.getAsString(); int points = (element = mappingObject.get("points")).isJsonNull() ? null : element.getAsInt(); element = mappingObject.get("monitorIDs"); ArrayList<String> monitorIDs = new ArrayList<String>(); if (element != null && !element.isJsonNull()) { JsonArray IDs = element.getAsJsonArray(); for (int k = 0; k < IDs.size(); k++) { String id = String.valueOf(IDs.get(k).getAsString()); monitorIDs.add(id); } } ChartMappings chartMapping = new ChartMappings(name, description, unit, type, points, monitorIDs); chartsList.add(chartMapping); } chartsMap.put(systemType, chartsList); } } jsonElement = json.getAsJsonObject().get("chartSettings"); if (jsonElement != null && !jsonElement.isJsonNull()) { JsonObject settingsJson = jsonElement.getAsJsonObject(); JsonElement element; chartProperties.timeSpan = (element = settingsJson.get("timeSpan")).isJsonNull() ? 0 : element.getAsInt(); chartProperties.theme = (element = settingsJson.get("theme")).isJsonNull() ? null : element.getAsString(); } return chartProperties; }
From source file:com.skysql.manager.api.CommandsDeserializer.java
License:Open Source License
public Commands deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException, NullPointerException { Commands commands = new Commands(); JsonElement jsonElement = json.getAsJsonObject().get("commands"); if (jsonElement.isJsonNull()) { commands.setDescriptions(null);/*from ww w . java 2 s.c o m*/ commands.setNames(null); commands.setSteps(null); } else { JsonArray array = jsonElement.getAsJsonArray(); int length = array.size(); LinkedHashMap<String, String> descriptions = new LinkedHashMap<String, String>(length); LinkedHashMap<String, String> names = new LinkedHashMap<String, String>(length); LinkedHashMap<String, String> steps = new LinkedHashMap<String, String>(length); for (int i = 0; i < length; i++) { JsonObject pair = array.get(i).getAsJsonObject(); String command = pair.get("command").getAsString(); descriptions.put(command, pair.get("description").getAsString()); names.put(command, command); steps.put(command, pair.get("steps").getAsString()); } commands.setDescriptions(descriptions); commands.setNames(names); commands.setSteps(steps); } return commands; }
From source file:com.skysql.manager.api.CommandStates.java
License:Open Source License
public CommandStates deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException, NullPointerException { CommandStates commandStates = new CommandStates(); JsonElement jsonElement = json.getAsJsonObject().get("commandStates"); if (jsonElement.isJsonNull()) { commandStates.setDescriptions(null); } else {//from w w w .jav a 2s . c o m JsonArray array = jsonElement.getAsJsonArray(); int length = array.size(); LinkedHashMap<String, String> descriptions = new LinkedHashMap<String, String>(length); List<CommandStates.States> validStates = Arrays.asList(CommandStates.States.values()); for (int i = 0; i < length; i++) { JsonObject pair = array.get(i).getAsJsonObject(); String state = pair.get("state").getAsString(); try { if (validStates.contains(CommandStates.States.valueOf(state))) { descriptions.put(state, pair.get("description").getAsString()); } } catch (IllegalArgumentException e) { new ErrorDialog(e, "Unknown Command State (" + state + ") found in API response"); throw new RuntimeException("Unknown Command State (" + state + ") found in API response"); } } commandStates.setDescriptions(descriptions); } return commandStates; }
From source file:com.skysql.manager.api.MonitorData.java
License:Open Source License
public MonitorData deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException, NullPointerException { MonitorData monitorData = new MonitorData(); JsonElement jsonElement = json.getAsJsonObject().get("monitor_data"); if (jsonElement.isJsonNull() || jsonElement.isJsonArray()) { return monitorData; }// w ww .ja va2 s. c om JsonObject jsonObject = jsonElement.getAsJsonObject(); if (jsonObject.has("timestamp")) { JsonElement jsonTime = jsonElement.getAsJsonObject().get("timestamp"); if (jsonTime != null && !jsonTime.isJsonNull()) { JsonArray array = jsonTime.getAsJsonArray(); int length = array.size(); ArrayList<Long> timeStamps = new ArrayList<Long>(length); for (int i = 0; i < length; i++) { Long timeStamp = array.get(i).getAsLong(); timeStamps.add(timeStamp); } monitorData.setTimeStamps(timeStamps); } } if (jsonObject.has("value")) { JsonElement jsonValue = jsonElement.getAsJsonObject().get("value"); if (jsonValue != null && !jsonValue.isJsonNull()) { JsonArray array = jsonValue.getAsJsonArray(); int length = array.size(); ArrayList<Number> avgPoints = new ArrayList<Number>(length); for (int i = 0; i < length; i++) { Double dataPoint = array.get(i).getAsDouble(); avgPoints.add(sanitize(dataPoint)); } monitorData.setAvgPoints(avgPoints); } } if (jsonObject.has("min")) { JsonElement jsonValue = jsonElement.getAsJsonObject().get("min"); if (jsonValue != null && !jsonValue.isJsonNull()) { JsonArray array = jsonValue.getAsJsonArray(); int length = array.size(); ArrayList<Number> minPoints = new ArrayList<Number>(length); for (int i = 0; i < length; i++) { Double dataPoint = array.get(i).getAsDouble(); minPoints.add(sanitize(dataPoint)); } monitorData.setMinPoints(minPoints); } } if (jsonObject.has("max")) { JsonElement jsonValue = jsonElement.getAsJsonObject().get("max"); if (jsonValue != null && !jsonValue.isJsonNull()) { JsonArray array = jsonValue.getAsJsonArray(); int length = array.size(); ArrayList<Number> maxPoints = new ArrayList<Number>(length); for (int i = 0; i < length; i++) { Double dataPoint = array.get(i).getAsDouble(); maxPoints.add(sanitize(dataPoint)); } monitorData.setMaxPoints(maxPoints); } } return monitorData; }
From source file:com.skysql.manager.api.MonitorDataRaw.java
License:Open Source License
public MonitorDataRaw deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException, NullPointerException { MonitorDataRaw monitorData = new MonitorDataRaw(); JsonElement jsonElement = json.getAsJsonObject().get("monitor_rawdata"); if (jsonElement.isJsonNull() || jsonElement.isJsonArray()) { return monitorData; }/*from www. j a va 2 s .c o m*/ JsonObject jsonObject = jsonElement.getAsJsonObject(); if (jsonObject.has("timestamp")) { JsonElement jsonTime = jsonElement.getAsJsonObject().get("timestamp"); if (jsonTime != null && !jsonTime.isJsonNull()) { JsonArray array = jsonTime.getAsJsonArray(); int length = array.size(); ArrayList<Long> timeStamps = new ArrayList<Long>(length); for (int i = 0; i < length; i++) { Long timeStamp = array.get(i).getAsLong(); timeStamps.add(timeStamp); } monitorData.setTimeStamps(timeStamps); } } if (jsonObject.has("value")) { JsonElement jsonValue = jsonElement.getAsJsonObject().get("value"); if (jsonValue != null && !jsonValue.isJsonNull()) { JsonArray array = jsonValue.getAsJsonArray(); int length = array.size(); ArrayList<Double> dataPoints = new ArrayList<Double>(length); for (int i = 0; i < length; i++) { Double dataPoint = array.get(i).getAsDouble(); dataPoints.add(dataPoint); } monitorData.setDataPoints(dataPoints); } } return monitorData; }
From source file:com.skysql.manager.api.NodeInfo.java
License:Open Source License
public NodeInfo deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException, NullPointerException { NodeInfo nodeInfo = new NodeInfo(); JsonElement element = json.getAsJsonObject().get("node"); if (element.isJsonNull()) { return null; } else {//from ww w . j a va 2 s. c o m JsonObject jsonObject = element.getAsJsonObject(); nodeInfo.setName(((element = jsonObject.get("name")) == null || element.isJsonNull()) ? null : element.getAsString()); nodeInfo.setState(((element = jsonObject.get("state")) == null || element.isJsonNull()) ? null : element.getAsString()); nodeInfo.setUpdated(((element = jsonObject.get("updated")) == null || element.isJsonNull()) ? null : element.getAsString()); nodeInfo.setHostname(((element = jsonObject.get("hostname")) == null || element.isJsonNull()) ? null : element.getAsString()); nodeInfo.setPublicIP(((element = jsonObject.get("publicip")) == null || element.isJsonNull()) ? null : element.getAsString()); nodeInfo.setPrivateIP(((element = jsonObject.get("privateip")) == null || element.isJsonNull()) ? null : element.getAsString()); nodeInfo.setPort(((element = jsonObject.get("port")) == null || element.isJsonNull()) ? null : element.getAsString()); nodeInfo.setInstanceID(((element = jsonObject.get("instanceid")) == null || element.isJsonNull()) ? null : element.getAsString()); nodeInfo.setDBUsername(((element = jsonObject.get("dbusername")) == null || element.isJsonNull()) ? null : element.getAsString()); nodeInfo.setDBPassword(((element = jsonObject.get("dbpassword")) == null || element.isJsonNull()) ? null : element.getAsString()); nodeInfo.setRepUsername( ((element = jsonObject.get("repusername")) == null || element.isJsonNull()) ? null : element.getAsString()); nodeInfo.setRepPassword( ((element = jsonObject.get("reppassword")) == null || element.isJsonNull()) ? null : element.getAsString()); nodeInfo.setLastMonitored( ((element = jsonObject.get("lastmonitored")) == null || element.isJsonNull()) ? null : element.getAsString()); if ((element = jsonObject.get("commands")) != null && !element.isJsonNull()) { Commands commands = APIrestful.getGson().fromJson("{\"commands\":" + element.toString() + "}", Commands.class); nodeInfo.setCommands(commands); } if ((element = jsonObject.get("monitorlatest")) != null && !element.isJsonNull()) { MonitorLatest monitorLatest = APIrestful.getGson().fromJson(element.toString(), MonitorLatest.class); nodeInfo.setMonitorLatest(monitorLatest); } if ((element = jsonObject.get("task")) != null && !element.isJsonNull() && !element.getAsJsonObject().entrySet().isEmpty()) { TaskInfo taskInfo = APIrestful.getGson().fromJson("{\"task\":" + element.toString() + "}", TaskInfo.class); TaskRecord taskRecord = taskInfo.getTasksList().get(0); nodeInfo.setTask(taskRecord); } } return nodeInfo; }
From source file:com.skysql.manager.api.NodeStates.java
License:Open Source License
public NodeStates deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException, NullPointerException { NodeStates nodeStates = new NodeStates(); JsonElement jsonElement = json.getAsJsonObject().get("nodestates"); if (jsonElement != null && !jsonElement.isJsonNull()) { LinkedHashMap<String, NodeStates> stateRecords = new LinkedHashMap<String, NodeStates>(); Set<Entry<String, JsonElement>> set = jsonElement.getAsJsonObject().entrySet(); Iterator<Entry<String, JsonElement>> iter = set.iterator(); while (iter.hasNext()) { Entry<String, JsonElement> entry = iter.next(); JsonElement element = entry.getValue(); String systemType = entry.getKey(); JsonArray statesArray = element.isJsonNull() ? null : element.getAsJsonArray(); NodeStates states = parseStates(systemType, statesArray); stateRecords.put(systemType, states); }//from w w w . j a v a 2 s . c om nodeStates.setNodeStates(stateRecords); } return nodeStates; }
From source file:com.skysql.manager.api.Schedule.java
License:Open Source License
public Schedule deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException, NullPointerException { Schedule schedule = new Schedule(); JsonArray array = null;//from w ww.j a va2 s . c o m int length = 0; if (json.getAsJsonObject().has("schedules")) { array = json.getAsJsonObject().get("schedules").getAsJsonArray(); length = array.size(); } else if (json.getAsJsonObject().has("schedule")) { length = 1; } else { return null; } LinkedHashMap<String, ScheduleRecord> scheduleList = new LinkedHashMap<String, ScheduleRecord>(length); schedule.setScheduleList(scheduleList); for (int i = 0; i < length; i++) { JsonObject scheduleObject = (array != null) ? array.get(i).getAsJsonObject() : json.getAsJsonObject().get("schedule").getAsJsonObject(); JsonElement element; String id = (element = scheduleObject.get("scheduleid")).isJsonNull() ? null : element.getAsString(); String command = (element = scheduleObject.get("command")).isJsonNull() ? null : element.getAsString(); String systemID = (element = scheduleObject.get("systemid")).isJsonNull() ? null : element.getAsString(); String nodeID = (element = scheduleObject.get("nodeid")).isJsonNull() ? null : element.getAsString(); String userID = (element = scheduleObject.get("username")).isJsonNull() ? null : element.getAsString(); String params = ((element = scheduleObject.get("parameters")).isJsonNull()) ? null : element.getAsJsonObject().toString().replaceAll("[\\{\\}\"]*", ""); String iCal = (element = scheduleObject.get("icalentry")).isJsonNull() ? null : element.getAsString(); String nextStart = (element = scheduleObject.get("nextstart")).isJsonNull() ? null : element.getAsString(); String created = (element = scheduleObject.get("created")).isJsonNull() ? null : element.getAsString(); String updated = (element = scheduleObject.get("updated")).isJsonNull() ? null : element.getAsString(); String state = (element = scheduleObject.get("state")) == null || element.isJsonNull() ? null : element.getAsString(); ScheduleRecord scheduleRecord = new ScheduleRecord(id, command, systemID, nodeID, userID, params, iCal, nextStart, created, updated, state); scheduleList.put(id, scheduleRecord); } return schedule; }
From source file:com.skysql.manager.api.SettingsValues.java
License:Open Source License
public SettingsValues deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException, NullPointerException { SettingsValues settingsValues = new SettingsValues(); JsonElement jsonElement = json.getAsJsonObject().get("applicationproperty"); if (jsonElement.isJsonNull()) { settingsValues.setValues(null);//from w ww . j a v a 2 s . c om } else { JsonObject jsonObject = (JsonObject) jsonElement; Set<Entry<String, JsonElement>> set = jsonObject.entrySet(); Iterator<Entry<String, JsonElement>> iter = set.iterator(); if (iter.hasNext()) { Entry<String, JsonElement> entry = iter.next(); String value = entry.getValue().getAsString(); settingsValues.setValues(value.split(",")); } } return settingsValues; }
From source file:com.skysql.manager.api.Steps.java
License:Open Source License
public Steps deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException, NullPointerException { Steps steps = new Steps(); JsonElement jsonElement = json.getAsJsonObject().get("command_steps"); if (jsonElement.isJsonNull()) { steps.setStepsList(null);//w ww . j av a2 s .c o m } else { JsonArray array = jsonElement.getAsJsonArray(); int length = array.size(); LinkedHashMap<String, String> stepsList = new LinkedHashMap<String, String>(length); for (int i = 0; i < length; i++) { JsonObject backupJson = array.get(i).getAsJsonObject(); JsonElement element; String id = (element = backupJson.get("step")).isJsonNull() ? null : element.getAsString(); String description = (element = backupJson.get("description")).isJsonNull() ? null : element.getAsString(); stepsList.put(id, description); } steps.setStepsList(stepsList); } return steps; }