Example #1
0
  private <T extends ParseObject> T parseData(JSONObject jsonObject) {

    @SuppressWarnings("unchecked")
    T po = (T) new ParseObject();

    Iterator<?> keys = jsonObject.keys();
    while (keys.hasNext()) {
      String key = (String) keys.next();
      Object obj = jsonObject.get(key);

      if (obj instanceof JSONObject) {
        JSONObject o = (JSONObject) obj;
        String type = o.getString("__type");

        if ("Date".equals(type)) {
          Date date = Parse.parseDate(o.getString("iso"));
          po.put(key, date);
        }

        if ("Bytes".equals(type)) {
          String base64 = o.getString("base64");
          po.put(key, base64);
        }

        if ("GeoPoint".equals(type)) {
          ParseGeoPoint gp = new ParseGeoPoint(o.getDouble("latitude"), o.getDouble("longitude"));
          po.put(key, gp);
        }

        if ("File".equals(type)) {
          ParseFile file = new ParseFile(o.getString("name"), o.getString("url"));
          po.put(key, file);
        }

        if ("Pointer".equals(type)) {}

      } else {
        if (Parse.isInvalidKey(key)) {
          setReservedKey(key, obj);
        } else {
          put(key, ParseDecoder.decode(obj));
        }
      }
    }

    po.isDirty = false;
    return po;
  }
Example #2
0
  protected void setData(JSONObject jsonObject, boolean disableChecks) {
    Iterator<?> it = jsonObject.keys();
    while (it.hasNext()) {
      String key = (String) it.next();
      Object value = jsonObject.opt(key);
      if (Parse.isInvalidKey(key)) {
        setReservedKey(key, value);
      } else {
        put(key, ParseDecoder.decode(value), disableChecks);
      }
    }

    this.isDirty = false;
    this.operations.clear();
    this.dirtyKeys.clear();
  }
Example #3
0
  public <T> List<T> getList(String key) {

    if (!this.data.containsKey(key)) {
      return null;
    }
    Object value = this.data.get(key);

    if ((value instanceof JSONArray)) {
      value = ParseDecoder.decode(value);
      put(key, value);
    }

    if (!(value instanceof List)) {
      return null;
    }

    List<T> returnValue = (List<T>) value;
    return returnValue;
  }