Package ar.com.restba.json

Examples of ar.com.restba.json.JsonObject


    if (this.mode == 'i') {
      this.mode = 'o';
    }
    if (this.mode == 'o' || this.mode == 'a') {
      this.append("{");
      this.push(new JsonObject());
      this.comma = false;
      return this;
    }
    throw new JsonException("Misplaced object.");
View Full Code Here


    case '"':
    case '\'':
      return nextString(c);
    case '{':
      back();
      return new JsonObject(this);
    case '[':
    case '(':
      back();
      return new JsonArray(this);
    }
View Full Code Here

  public static void main(String[] args) {

    RestBAClient dataBairesClient = new DefaultRestBAClient();
    String query = "gcba/metadata/_search?&from=0";

    JsonObject q = dataBairesClient.executeQuery(query, JsonObject.class);
   
    System.out.println("JSON object: " + q.toString());
  }
View Full Code Here

    if (null == resources) {
      throw new RuntimeException("resources can't be null");
    }

    for (int i = 0; i < resources.length(); i++) {
      JsonObject jsonObject = resources.getJsonObject(i);
      if (id.equals(jsonObject.getString("id"))) {
        return jsonObject;
      }
    }
    throw new RuntimeException("Could not find resource by id: " + id);
  }
View Full Code Here

    if (json == null)
      throw new FacebookJsonMappingException(
          "You must supply non-null connection JSON.");

    JsonObject jsonObject = null;

    try {
      jsonObject = new JsonObject(json);
    } catch (JsonException e) {
      throw new FacebookJsonMappingException(
          "The connection JSON you provided was invalid: " + json, e);
    }

    // Pull out data
    JsonObject hits = jsonObject.getJsonObject("hits");
    long total = hits.getLong("total");
    maxPages = ((int) Math.ceil(total / 10.0));

    JsonArray jsonData = hits.getJsonArray("hits");

    for (int i = 0; i < jsonData.length(); i++) {
      T t;
      JsonObject objectToMap = jsonData.getJsonObject(i).getJsonObject(
          "_source");
      String id = jsonData.getJsonObject(i).getString("_id");
      objectToMap.putOnce("_id", id);
      if (connectionType.equals(ar.com.restba.json.JsonObject.class)) {
        t = (T) objectToMap;
      } else if (connectionType.equals(com.restfb.json.JsonObject.class)) {
        throw new RestBAException(
            "The json object Type is wrong,"
                + "please use instead ar.com.restba.json.JsonObject.class");
      } else {
        t = restBaClient.getJsonMapper().toJavaObject(
            objectToMap.toString(), connectionType);
      }

      data.add(t);
    }
View Full Code Here

    try {
      // If this is not an object, it's not an error response.
      if (!json.startsWith("{"))
        return;

      JsonObject errorObject = null;

      // We need to swallow exceptions here because it's possible to get a legit
      // Facebook response that contains illegal JSON (e.g.
      // users.getLoggedInUser returning 1240077) - we're only interested in
      // whether or not there's an error_code field present.
      try {
        errorObject = new JsonObject(json);
      } catch (JsonException e) {}

      if (errorObject == null || !errorObject.has(LEGACY_ERROR_CODE_ATTRIBUTE_NAME))
        return;

      throw legacyFacebookExceptionMapper.exceptionForTypeAndMessage(
        errorObject.getInt(LEGACY_ERROR_CODE_ATTRIBUTE_NAME), null,
        errorObject.getString(LEGACY_ERROR_MSG_ATTRIBUTE_NAME));
    } catch (JsonException e) {
      throw new FacebookJsonMappingException("Unable to process the Facebook API response", e);
    }
  }
View Full Code Here

    verifyParameterPresence("queries", queries);

    if (queries.keySet().size() == 0)
      throw new IllegalArgumentException("You must specify at least one query.");

    JsonObject jsonObject = new JsonObject();

    for (Entry<String, String> entry : queries.entrySet()) {
      if (isBlank(entry.getKey()) || isBlank(entry.getValue()))
        throw new IllegalArgumentException("Provided queries must have non-blank keys and values. " + "You provided: "
            + queries);

      try {
        jsonObject.put(trimToEmpty(entry.getKey()), trimToEmpty(entry.getValue()));
      } catch (JsonException e) {
        // Shouldn't happen unless bizarre input is provided
        throw new IllegalArgumentException("Unable to convert " + queries + " to JSON.", e);
      }
    }

    return jsonObject.toString();
  }
View Full Code Here

            "The list of IDs cannot contain blank strings.");
      ids.set(i, id);
    }

    try {
      JsonObject jsonObject = new JsonObject(makeRequest(
          "",
          parametersWithAdditionalParameter(
              Parameter.with(IDS_PARAM_NAME, join(ids)),
              parameters)));

      return objectType.equals(JsonObject.class) ? (T) jsonObject
          : jsonMapper
              .toJavaObject(jsonObject.toString(), objectType);
    } catch (JsonException e) {
      throw new FacebookJsonMappingException(
          "Unable to map connection JSON to Java objects", e);
    }
  }
View Full Code Here

          null,
          parametersWithAdditionalParameter(Parameter.with(
              QUERIES_PARAM_NAME, queriesToJson(queries)),
              parameters)));

      JsonObject normalizedJson = new JsonObject();

      for (int i = 0; i < jsonArray.length(); i++) {
        JsonObject jsonObject = jsonArray.getJsonObject(i);

        // For empty resultsets, Facebook will return an empty object
        // instead of
        // an empty list. Hack around that here.
        JsonArray resultsArray = jsonObject.get("fql_result_set") instanceof JsonArray ? jsonObject
            .getJsonArray("fql_result_set") : new JsonArray();

        normalizedJson.put(jsonObject.getString("name"), resultsArray);
      }

      return objectType.equals(JsonObject.class) ? (T) normalizedJson
          : jsonMapper.toJavaObject(normalizedJson.toString(),
              objectType);
View Full Code Here

      // connections and in a few other places, e.g. comments on the Post
      // object.
      // Doing this simplifies mapping, so we don't have to worry about having a
      // little placeholder object that only has a "data" value.
      try {
        JsonObject jsonObject = new JsonObject(json);
        String[] fieldNames = JsonObject.getNames(jsonObject);

        if (fieldNames != null) {
          boolean hasSingleDataProperty = fieldNames.length == 1 && "data".equals(fieldNames[0]);
          Object jsonDataObject = jsonObject.get("data");

          if (!hasSingleDataProperty && !(jsonDataObject instanceof JsonArray))
            if (jsonMappingErrorHandler.handleMappingError(json, type, null))
              return null;
            else
View Full Code Here

TOP

Related Classes of ar.com.restba.json.JsonObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.