@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()); } } } }
@JsonMappingCompleted void fillAdditionalValues(JsonMapper mapper) { if (this.data != null) { JsonObject dataObject = Json.parse(this.data).asObject(); if (dataObject.get("rating") != null) { JsonObject rating = dataObject.get("rating").asObject(); if (rating != null) { ratingValue = rating.get("value").asDouble(); ratingScale = rating.get("scale").asLong(); language = dataObject.get("language").asString(); isDraft = dataObject.get("is_draft").asBoolean(); reviewText = dataObject.get("review_text").asString(); place = mapper.toJavaObject(dataObject.get("generic_place").toString(), Place.class); } else if (dataObject.get("seller") != null) { place = mapper.toJavaObject(dataObject.get("seller").toString(), Place.class); String typeString = dataObject.get("recommendation_type").asString(); recommendationType = RecommendationType.valueOf(typeString.toUpperCase()); } catch (IllegalArgumentException iae) {
if (rawValue.isNull()) { return null; if (rawValue.isArray() && rawValue.asArray().isEmpty()) { MAPPER_LOGGER.trace("Coercing an empty JSON array to an empty string for {}", fieldWithAnnotation); return toJavaList(rawValue.toString(), getFirstParameterizedTypeArgument(fieldWithAnnotation.getField())); return convertJsonObjectToMap(rawValue.toString(), fieldWithAnnotation.getField()); Class<? extends Enum> enumType = type.asSubclass(Enum.class); try { return Enum.valueOf(enumType, rawValue.asString()); } catch (IllegalArgumentException iae) { MAPPER_LOGGER.debug("Cannot map string {} to enum {}, try fallback toUpperString next...", rawValue.asString(), enumType.getName()); return Enum.valueOf(enumType, rawValue.asString().toUpperCase()); } catch (IllegalArgumentException iae) { MAPPER_LOGGER.debug("Mapping string {} to enum {} not possible", rawValue.asString(), enumType.getName());
public ProfilePictureSource convertPicture(String rawPicture) { if (rawPicture == null) { return null; } try { JsonValue jsonValue = Json.parse(rawPicture); if (!jsonValue.isObject()) { return null; } String picJson = jsonValue.asObject().get("data").toString(); return this.mapper.toJavaObject(picJson, ProfilePictureSource.class); } catch (ParseException pe) { return null; } } }
@Override public boolean deleteObject(String object, Parameter... parameters) { verifyParameterPresence("object", object); String responseString = makeRequest(object, true, true, null, parameters); try { JsonValue jObj = Json.parse(responseString); boolean success = false; if (jObj.isObject()) { if (jObj.asObject().get("success") != null) { success = jObj.asObject().get("success").asBoolean(); } if (jObj.asObject().get("result") != null) { success = jObj.asObject().get("result").asString().contains("Successfully deleted"); } } else { success = jObj.asBoolean(); } return success; } catch (ParseException jex) { CLIENT_LOGGER.trace("no valid JSON returned while deleting a object, using returned String instead", jex); return "true".equals(responseString); } }
public ListJsonChangeValue(List<JsonValue> values) { value = new ArrayList<>(); for (JsonValue jsonValue : values) { value.add(jsonValue.asObject()); } }
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); }
JsonValue andList = ruleJson.get(key); RuleOpAnd rOp = new RuleOpAnd(key); if (andList.isArray()) { for (JsonValue item : andList.asArray()) { Rule r = RuleFactory.createRuleFromJson(item.asObject()); rOp.getRuleList().add(r); JsonValue andList = ruleJson.get(key); RuleOpOr rOp = new RuleOpOr(key); if (andList.isArray()) { for (JsonValue item : andList.asArray()) { Rule r = RuleFactory.createRuleFromJson(item.asObject()); rOp.getRuleList().add(r);
JsonObject jsonObject = Json.parse(json).asObject(); List<String> fieldNames = jsonObject.names(); JsonArray jsonArray = Json.parse(json).asArray(); List<T> list = new ArrayList<>(jsonArray.size()); for (JsonValue jsonValue: jsonArray) { if (jsonValue.isString() && innerJson.startsWith("[")) { innerJson = '"' + innerJson + '"';
jsonObject = Json.parse(json).asObject(); } catch (ParseException e) { throw new FacebookJsonMappingException("The connection JSON you provided was invalid: " + json, e); JsonArray jsonData = jsonObject.get("data").asArray(); List<T> dataItem = new ArrayList<>(jsonData.size()); for (JsonValue jsonValue : jsonData) { dataItem.add(connectionType.equals(JsonObject.class) ? (T) jsonValue : facebookClient.getJsonMapper().toJavaObject(jsonValue.toString(), connectionType)); JsonObject jsonPaging = jsonObject.get("paging").asObject(); previousPageUrl = fixProtocol(jsonPaging.getString("previous", null)); nextPageUrl = fixProtocol(jsonPaging.getString("next", null)); JsonObject jsonCursors = jsonPaging.get("cursors").asObject(); beforeCursor = jsonCursors.getString("before", null); afterCursor = jsonCursors.getString("after", null); JsonObject jsonSummary = jsonObject.get("summary").asObject(); totalCount = jsonSummary.get("total_count") != null ? jsonSummary.getLong("total_count", 0L) : null; } else {
/** * 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 ""; }
/** * Reads a JSON object from the given string. * * @param string * the string that contains the JSON object * @return the JSON object that has been read * @throws ParseException * if the input is not valid JSON * @throws UnsupportedOperationException * if the input does not contain a JSON object * @deprecated Use {@link Json#parse(String)}{@link JsonValue#asObject() .asObject()} instead */ @Deprecated public static JsonObject readFrom(String string) { return JsonValue.readFrom(string).asObject(); }
/** * Reads a JSON array from the given string. * * @param string * the string that contains the JSON array * @return the JSON array that has been read * @throws ParseException * if the input is not valid JSON * @throws UnsupportedOperationException * if the input does not contain a JSON array * @deprecated Use {@link Json#parse(String)}{@link JsonValue#asArray() .asArray()} instead */ @Deprecated public static JsonArray readFrom(String string) { return JsonValue.readFrom(string).asArray(); }
private AdsImageCropsSpec createSpecFromString(String input) { AdsImageCropsSpec spec = null; if (input != null) { spec = new AdsImageCropsSpec(); JsonValue ar = Json.parse(input); JsonArray outerArray = ar.asArray(); JsonArray leftTop = outerArray.get(0).asArray(); spec.setLeft(leftTop.get(0).asLong()); spec.setTop(leftTop.get(1).asLong()); JsonArray rightBottom = outerArray.get(1).asArray(); spec.setRight(rightBottom.get(0).asLong()); spec.setBottom(rightBottom.get(1).asLong()); } return spec; }