/** * add change count value, if summary is set and count is empty */ private void fillTotalCount(JsonObject summary) { if (totalCount == 0 && summary != null && summary.get("total_count") != null) { totalCount = summary.getLong("total_count", totalCount); } }
/** * Get the long value associated with a key. If the number value is too long * for a long, it will be clipped. * * @param key A key string. * @return The long value. * @throws com.restfb.json.JsonException if the key is not found or if the value cannot be converted to a * long. */ public long getLong(String key) throws JsonException { Object o = get(key); return o instanceof Number ? ((Number) o).longValue() : (long) getDouble(key); }
/** * Get the string associated with a key. * * @param key A key string. * @return A string which is the value. * @throws com.restfb.json.JsonException if the key is not found. */ public String getString(String key) throws JsonException { return get(key).toString(); }
protected ExceptionInformation createFacebookResponseTypeAndMessageContainer(JsonObject errorObject, Integer httpStatusCode) { JsonObject innerErrorObject = errorObject.get(ERROR_ATTRIBUTE_NAME).asObject(); // If there's an Integer error code, pluck it out. Integer errorCode = innerErrorObject.get(ERROR_CODE_ATTRIBUTE_NAME) != null ? toInteger(innerErrorObject.get(ERROR_CODE_ATTRIBUTE_NAME).toString()) : null; Integer errorSubcode = innerErrorObject.get(ERROR_SUBCODE_ATTRIBUTE_NAME) != null ? toInteger(innerErrorObject.get(ERROR_SUBCODE_ATTRIBUTE_NAME).toString()) : null; return new ExceptionInformation(errorCode, errorSubcode, httpStatusCode, innerErrorObject.getString(ERROR_TYPE_ATTRIBUTE_NAME, null), innerErrorObject.get(ERROR_MESSAGE_ATTRIBUTE_NAME).asString(), innerErrorObject.getString(ERROR_USER_TITLE_ATTRIBUTE_NAME, null), innerErrorObject.getString(ERROR_USER_MSG_ATTRIBUTE_NAME, null), innerErrorObject.getBoolean(ERROR_IS_TRANSIENT_NAME, false), errorObject); }
/** * Gets the Facebook API error {@code fbtrace_id}. * * Internal support identifier. When reporting a bug related to a Graph API call, include the fbtrace_id to help us * find log data for debugging. * * @return the Facebook API error {@code fbtrace_id} */ public String getFbtraceId() { if (getRawErrorJson() != null && getRawErrorJson().get("error").isObject()) { JsonObject errorJson = getRawErrorJson().get("error").asObject(); return errorJson.getString("fbtrace_id", ""); } return ""; }
/** * add change count value, if summary is set and count is empty */ private void fillTotalCount(JsonObject summary) { if (totalCount == 0 && summary != null && summary.get("total_count") != null) { totalCount = summary.getLong("total_count", totalCount); } if (openGraphCount != 0) { totalCount = openGraphCount; } }
/** * Get the int value associated with a key. If the number value is too large * for an int, it will be clipped. * * @param key A key string. * @return The integer value. * @throws com.restfb.json.JsonException if the key is not found or if the value cannot be converted to an * integer. */ public int getInt(String key) throws JsonException { Object o = get(key); return o instanceof Number ? ((Number) o).intValue() : (int) getDouble(key); }
/** * fill <code>has_liked</code> from summary, in case of open graph object use user_likes instead */ private void fillHasLiked(JsonObject summary) { if (summary != null && summary.get("has_liked") != null) { hasLiked = summary.get("has_liked").asBoolean(); } if (hasLiked == null && openGraphUserLikes != null) { hasLiked = openGraphUserLikes; } }
/** * set total count if summary is present */ private void fillTotalCount(JsonObject summary) { if (totalCount == 0 && summary != null && summary.get("total_count") != null) { totalCount = summary.getLong("total_count", totalCount); } if (totalCount == 0 && count != 0) { totalCount = count; } }
/** * Get the JsonObject value associated with a key. * * @param key A key string. * @return A JsonObject which is the value. * @throws com.restfb.json.JsonException if the key is not found or if the value is not a JsonObject. */ public JsonObject getJsonObject(String key) throws JsonException { Object o = get(key); if (o instanceof JsonObject) { return (JsonObject) o; } throw new JsonException("JsonObject[" + quote(key) + "] is not a JsonObject."); }
/** * Get the JsonArray value associated with a key. * * @param key A key string. * @return A JsonArray which is the value. * @throws com.restfb.json.JsonException if the key is not found or if the value is not a JsonArray. */ public JsonArray getJsonArray(String key) throws JsonException { Object o = get(key); if (o instanceof JsonArray) { return (JsonArray) o; } throw new JsonException("JsonObject[" + quote(key) + "] is not a JsonArray."); }
@JsonMappingCompleted void convertTags() { if (rawTags != null) { JsonValue parsedObject = Json.parse(rawTags); if (parsedObject.isObject() && parsedObject.asObject().get("data").isArray()) { for (JsonValue tagObject : parsedObject.asObject().get("data").asArray()) { tags.add(tagObject.asObject().get("name").asString()); } } } }
private static Rule createRuleData(JsonObject ruleJson, String key) { RuleData rData = new RuleData(key); rData.setOperator((RuleOp) RuleFactory.createRuleFromJson(ruleJson.get(key).asObject())); return rData; }
@JsonMappingCompleted private void convertList(JsonMapper mapper) { if (rawRegionsString != null) { JsonValue jsonValue = Json.parse(rawRegionsString); if (jsonValue.isObject()) { JsonObject rawRegions = jsonValue.asObject(); for (String key : rawRegions.names()) { String region = rawRegions.get(key).toString(); regions.add(mapper.toJavaObject(region, KeyedType.class)); } } } }
@JsonMappingCompleted protected void convertLabels(JsonMapper jsonMapper) { JsonObject rawLabels = null; if (this.rawLabels != null) { JsonValue jsonValue = Json.parse(this.rawLabels); if (jsonValue.isObject()) { rawLabels = jsonValue.asObject(); } } if (rawLabels != null && rawLabels.isObject()) { String innerLabelsString = rawLabels.get("data").toString(); labels = jsonMapper.toJavaList(innerLabelsString, PageLabel.class); } }
/** * @see com.restfb.FacebookClient#debugToken(java.lang.String) */ @Override public DebugTokenInfo debugToken(String inputToken) { verifyParameterPresence("inputToken", inputToken); String response = makeRequest("/debug_token", Parameter.with("input_token", inputToken)); try { JsonObject json = Json.parse(response).asObject(); JsonObject data = json.get("data").asObject(); return getJsonMapper().toJavaObject(data.toString(), DebugTokenInfo.class); } catch (Exception t) { throw new FacebookResponseContentException("Unable to parse JSON from response.", t); } }