@Override public Operator deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if (JsonNull.INSTANCE.equals(json)) return null; throw new UnsupportedOperationException("Deserializing operators is not yet supported."); } }
private void checWarnings(JsonObject response) throws IOException { if (!JsonNull.INSTANCE.equals(response.get("Warnings"))) { throw new IOException("response warnings: " + response.toString()); } }
/** * A helper method that gets a JSON object member value after making sure it exists and has a valid value. Useful when * a member value should present to proceed. * @param object A JSON object to get a member value from * @param memberName The name of a member to get value of * @return {@link JsonElement} value read from the given member * @throws JsonParseException When the specified member does not exist or have a value. */ public static JsonElement getOrDie(JsonObject object, String memberName) throws JsonParseException { if (object.has(memberName)) { JsonElement element = object.get(memberName); if (!JsonNull.INSTANCE.equals(element)) { return element; } } throw new JsonParseException("Field '" + memberName + "' not found in JSON object '" + object + "'"); } }
/** * A helper method that gets a JSON object member value after making sure it exists and has a valid value. Useful when * a member value should present to proceed. * @param object A JSON object to get a member value from * @param memberName The name of a member to get value of * @return {@link JsonElement} value read from the given member * @throws JsonParseException When the specified member does not exist or have a value. */ public static JsonElement getOrDie(JsonObject object, String memberName) throws JsonParseException { if (object.has(memberName)) { JsonElement element = object.get(memberName); if (!JsonNull.INSTANCE.equals(element)) { return element; } } throw new JsonParseException("Field '" + memberName + "' not found in JSON object '" + object + "'"); } }
public static JsonElement asJson(JsonElement json, Object... path) { JsonElement ret = get(json, path[0].toString()); if (path.length == 1) { if (JsonNull.INSTANCE.equals(ret)) { ret = null; } return ret; } if (ret.isJsonObject() || ret.isJsonArray()) { JsonElement head = ret.getAsJsonObject(); return asJson(head, Arrays.copyOfRange(path, 1, path.length)); } return null; }
@Override public JsonStringWrapper read(JsonReader in) throws IOException { JsonElement jsonElement = Streams.parse(in); return !JsonNull.INSTANCE.equals(jsonElement) ? new JsonStringWrapper(jsonElement.toString()) : null; } }
Schema.Type type = schema.getType(); if (object == null || JsonNull.INSTANCE.equals(object)) { return null; } else if (object instanceof JsonPrimitive) {