/** * Get an optional int value associated with a key, or the default if there is * no such key or if the value is not a number. If the value is a string, an * attempt will be made to evaluate it as a number. * * @param key A key string. * @param defaultValue The default. * @return An object which is the value. */ public int optInt(String key, int defaultValue) { try { return getInt(key); } catch (Exception e) { return defaultValue; } }
@JsonMappingCompleted void fillCounts() { if (this.share != null) { JsonObject shareObject = Json.parse(this.share).asObject(); commentCount = shareObject.getInt("comment_count", commentCount); shareCount = shareObject.getInt("share_count", shareCount); } if (this.engagement != null) { JsonObject engagementObject = Json.parse(this.engagement).asObject(); commentCount = engagementObject.getInt("comment_count", commentCount); shareCount = engagementObject.getInt("share_count", shareCount); reactionCount = engagementObject.getInt("reaction_count", reactionCount); commentPluginCount = engagementObject.getInt("comment_plugin_count", commentPluginCount); } }
private HeaderUsage createUsage(String usageInformation) { if (StringUtils.isBlank(usageInformation)) { return null; } try { JsonObject jsonValue = Json.parse(usageInformation).asObject(); return new HeaderUsage(jsonValue.getInt("call_count", -1), jsonValue.getInt("total_time", -1), jsonValue.getInt("total_cputime", -1)); } catch (Exception e) { return new HeaderUsage(usageInformation); } }
return new Integer(jsonObject.getInt(facebookFieldName)); if (Boolean.class.equals(type) || Boolean.TYPE.equals(type)) return new Boolean(jsonObject.getBoolean(facebookFieldName));
return; throw new FacebookResponseStatusException(errorObject.getInt(LEGACY_ERROR_CODE_ATTRIBUTE_NAME), errorObject.getString(LEGACY_ERROR_MSG_ATTRIBUTE_NAME)); } catch (JsonException e) {
@Override public void throwBatchFacebookResponseStatusExceptionIfNecessary(String json, Integer httpStatusCode) { try { skipResponseStatusExceptionParsing(json); JsonObject errorObject = silentlyCreateObjectFromString(json); if (errorObject == null || errorObject.get(BATCH_ERROR_ATTRIBUTE_NAME) == null || errorObject.get(BATCH_ERROR_DESCRIPTION_ATTRIBUTE_NAME) == null) return; ExceptionInformation container = new ExceptionInformation(errorObject.getInt(BATCH_ERROR_ATTRIBUTE_NAME, 0), httpStatusCode, errorObject.getString(BATCH_ERROR_DESCRIPTION_ATTRIBUTE_NAME, null), errorObject); throw graphFacebookExceptionMapper.exceptionForTypeAndMessage(container); } catch (ParseException e) { throw new FacebookJsonMappingException("Unable to process the Facebook API response", e); } catch (ResponseErrorJsonParsingException ex) { // do nothing here } }