List of usage examples for com.google.gson JsonElement isJsonNull
public boolean isJsonNull()
From source file:fr.zcraft.MultipleInventories.snaphots.PlayerSnapshot.java
License:Open Source License
private static boolean isNull(final JsonObject element, final String child) { final JsonElement childElement = element.get(child); return childElement == null || childElement.isJsonNull(); }
From source file:goldwatch_checker.PlayerData.java
License:Open Source License
/** * Opens connection to local OWAPI server, queries new data for this Player * @return true if player exists on server, false otherwise * @throws IOException /* w w w . j a v a 2 s .c o m*/ */ public PlayerData GetDataFromServer() throws IOException { if (json.isEmpty()) { CreateServerConn(); } JsonParser p = new JsonParser(); JsonElement e = p.parse(json); if (!e.isJsonNull()) { Date today = new Date(); m_last_chk = new GregorianCalendar(); m_last_chk.setTime(today); try { int sr = e.getAsJsonObject().get(m_region).getAsJsonObject().get("stats").getAsJsonObject() .get("competitive").getAsJsonObject().get("overall_stats").getAsJsonObject().get("comprank") .getAsInt(); m_lastRank = Integer.valueOf(sr); } catch (IllegalStateException ex) { m_lastRank = null; } catch (UnsupportedOperationException ex) { m_lastRank = null; } if (m_firstRank == null) m_firstRank = m_lastRank; try { m_highestTier = PlayerTier.Factory(e.getAsJsonObject().get(m_region).getAsJsonObject().get("stats") .getAsJsonObject().get("competitive").getAsJsonObject().get("overall_stats") .getAsJsonObject().get("tier").getAsString()); } catch (UnsupportedOperationException ex) { m_highestTier = PlayerTier.INVALID; } m_qphoursplayed = ComputeQuickplayTimePlayed(); m_level = GetLevel(); m_compMatchesPlayed = e.getAsJsonObject().get(m_region).getAsJsonObject().get("stats").getAsJsonObject() .get("competitive").getAsJsonObject().get("overall_stats").getAsJsonObject().get("games") .getAsInt(); return this; } return null; }
From source file:goldwatch_checker.PlayerData.java
License:Open Source License
/** * * @return/* w ww .j av a 2s .com*/ */ public Float ComputeQuickplayTimePlayed() { JsonParser p = new JsonParser(); JsonElement e = p.parse(json); float time = 0.0f; if (e.isJsonObject()) { JsonElement list = e.getAsJsonObject().get(m_region); if (!list.isJsonNull()) { for (HeroEnum h : HeroEnum.values()) { time += list.getAsJsonObject().get("heroes").getAsJsonObject().get("playtime").getAsJsonObject() .get("quickplay").getAsJsonObject().get(h.GetName()).getAsFloat(); } } } return time; }
From source file:goldwatch_checker.PlayerData.java
License:Open Source License
/** * * @return//w ww . j a v a2 s . c o m */ public Float GetCompTimePlayed() { JsonParser p = new JsonParser(); JsonElement e = p.parse(json); float time = 0.0f; if (e.isJsonObject()) { JsonElement list = e.getAsJsonObject().get(m_region); if (!list.isJsonNull()) { for (HeroEnum h : HeroEnum.values()) { try { time += list.getAsJsonObject().get("heroes").getAsJsonObject().get("playtime") .getAsJsonObject().get("competitive").getAsJsonObject().get(h.GetName()) .getAsFloat(); } catch (IllegalStateException ex) { //TODO: not a json object handler? } } } } return time; }
From source file:goldwatch_checker.PlayerData.java
License:Open Source License
private Integer GetLevel() throws IllegalStateException { JsonParser p = new JsonParser(); JsonElement e = p.parse(json); int maxLevel = Integer.MIN_VALUE; if (!e.isJsonNull()) { for (String r : s_regions) { if (!e.getAsJsonObject().get(r).isJsonNull()) { int level = 100 * e.getAsJsonObject().get(r).getAsJsonObject().get("stats").getAsJsonObject() .get("competitive").getAsJsonObject().get("overall_stats").getAsJsonObject() .get("prestige").getAsInt(); level += e.getAsJsonObject().get(r).getAsJsonObject().get("stats").getAsJsonObject() .get("competitive").getAsJsonObject().get("overall_stats").getAsJsonObject() .get("level").getAsInt(); if (maxLevel < level) maxLevel = level;//w w w . j ava 2 s . c om } } } return (maxLevel > 25) ? maxLevel : Integer.MAX_VALUE; }
From source file:hd3gtv.mydmam.metadata.container.ContainerOperations.java
License:Open Source License
public static JsonObject getJsonObject(JsonElement json, boolean can_null) throws JsonParseException { if (json.isJsonNull()) { if (can_null) { return null; } else {/*from ww w .j a v a 2s .co m*/ throw new JsonParseException("Json element is null"); } } if (json.isJsonObject() == false) { throw new JsonParseException("Json element is not an object: " + json.toString()); } return (JsonObject) json.getAsJsonObject(); }
From source file:hdm.stuttgart.esell.router.GeneralObjectDeserializer.java
License:Apache License
public Object deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if (json.isJsonNull()) { return null; } else if (json.isJsonPrimitive()) { JsonPrimitive primitive = json.getAsJsonPrimitive(); if (primitive.isString()) { return primitive.getAsString(); } else if (primitive.isNumber()) { return primitive.getAsNumber(); } else if (primitive.isBoolean()) { return primitive.getAsBoolean(); }/* w ww . ja va 2 s . co m*/ } else if (json.isJsonArray()) { JsonArray array = json.getAsJsonArray(); Object[] result = new Object[array.size()]; int i = 0; for (JsonElement element : array) { result[i] = deserialize(element, null, context); ++i; } return result; } else if (json.isJsonObject()) { JsonObject object = json.getAsJsonObject(); Map<String, Object> result = new HashMap<String, Object>(); for (Map.Entry<String, JsonElement> entry : object.entrySet()) { Object value = deserialize(entry.getValue(), null, context); result.put(entry.getKey(), value); } return result; } else { throw new JsonParseException("Unknown JSON type for JsonElement " + json.toString()); } return null; }
From source file:io.flutter.inspector.DiagnosticsNode.java
License:Open Source License
/** * Returns a reference to the value the DiagnosticsNode object is describing. */// w ww .j a v a 2 s . co m public InspectorInstanceRef getValueRef() { final JsonElement valueId = json.get("valueId"); return new InspectorInstanceRef(valueId.isJsonNull() ? null : valueId.getAsString()); }
From source file:io.flutter.inspector.DiagnosticsPathNode.java
License:Open Source License
public ArrayList<DiagnosticsNode> getChildren() { final ArrayList<DiagnosticsNode> children = new ArrayList<>(); final JsonElement childrenElement = json.get("children"); if (childrenElement.isJsonNull()) { return children; }// w w w . j a va2 s . co m final JsonArray childrenJson = childrenElement.getAsJsonArray(); for (int i = 0; i < childrenJson.size(); ++i) { children.add(new DiagnosticsNode(childrenJson.get(i).getAsJsonObject(), inspectorService, false)); } return children; }
From source file:io.flutter.inspector.DiagnosticsPathNode.java
License:Open Source License
/** * Returns the index of the child that continues the path if any. *///from w w w .java 2 s.co m public int getChildIndex() { final JsonElement childIndex = json.get("childIndex"); if (childIndex.isJsonNull()) { return -1; } return childIndex.getAsInt(); }