@Test public void testEncodeToJSON() throws Exception { ParseObject parent = new ParseObject("Parent"); ParseRelation relation = new ParseRelation(parent, "key"); relation.setTargetClass("Test"); ParseObject object = new ParseObject("Test"); object.setObjectId("objectId"); relation.addKnownObject(object); JSONObject json = relation.encodeToJSON(PointerEncoder.get()); assertEquals("Relation", json.getString("__type")); assertEquals("Test", json.getString("className")); JSONArray knownObjectsArray = json.getJSONArray("objects"); assertEquals( (JSONObject) PointerEncoder.get().encode(object), knownObjectsArray.getJSONObject(0), JSONCompareMode.NON_EXTENSIBLE); }
JSONObject encodeToJSON(ParseEncoder objectEncoder) throws JSONException { synchronized (mutex) { JSONObject relation = new JSONObject(); relation.put("__type", "Relation"); relation.put("className", targetClass); JSONArray knownObjectsArray = new JSONArray(); for (ParseObject knownObject : knownObjects) { try { knownObjectsArray.put(objectEncoder.encodeRelatedObject(knownObject)); } catch (Exception e) { } } relation.put("objects", knownObjectsArray); return relation; } }
ParseRelation implements Parcelable { JSONObject encodeToJSON(ParseEncoder objectEncoder) throws JSONException { synchronized (mutex) { JSONObject relation = new JSONObject(); relation.put("__type", "Relation"); relation.put("className", targetClass); JSONArray knownObjectsArray = new JSONArray(); for (ParseObject knownObject : knownObjects) { try { knownObjectsArray.put(objectEncoder.encodeRelatedObject(knownObject)); } catch (Exception e) { } } relation.put("objects", knownObjectsArray); return relation; } } }
ParseRelation implements Parcelable { JSONObject encodeToJSON(ParseEncoder objectEncoder) throws JSONException { synchronized (mutex) { JSONObject relation = new JSONObject(); relation.put("__type", "Relation"); relation.put("className", targetClass); JSONArray knownObjectsArray = new JSONArray(); for (ParseObject knownObject : knownObjects) { try { knownObjectsArray.put(objectEncoder.encodeRelatedObject(knownObject)); } catch (Exception e) { } } relation.put("objects", knownObjectsArray); return relation; } } ParseRelation(ParseObject parent, String key);   ParseRelation(String targetClass);   ParseRelation(JSONObject jsonObject, ParseDecoder decoder);   ParseRelation(Parcel source, ParseParcelDecoder decoder); }
ParseRelation implements Parcelable { JSONObject encodeToJSON(ParseEncoder objectEncoder) throws JSONException { synchronized (mutex) { JSONObject relation = new JSONObject(); relation.put("__type", "Relation"); relation.put("className", targetClass); JSONArray knownObjectsArray = new JSONArray(); for (ParseObject knownObject : knownObjects) { try { knownObjectsArray.put(objectEncoder.encodeRelatedObject(knownObject)); } catch (Exception e) { } } relation.put("objects", knownObjectsArray); return relation; } } ParseRelation(ParseObject parent, String key);   ParseRelation(String targetClass);   ParseRelation(JSONObject jsonObject, ParseDecoder decoder);   ParseRelation(Parcel source, ParseParcelDecoder decoder); void add(T object); void remove(T object); ParseQuery<T> getQuery(); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); }
ParseRelation implements Parcelable { JSONObject encodeToJSON(ParseEncoder objectEncoder) throws JSONException { synchronized (mutex) { JSONObject relation = new JSONObject(); relation.put("__type", "Relation"); relation.put("className", targetClass); JSONArray knownObjectsArray = new JSONArray(); for (ParseObject knownObject : knownObjects) { try { knownObjectsArray.put(objectEncoder.encodeRelatedObject(knownObject)); } catch (Exception e) { } } relation.put("objects", knownObjectsArray); return relation; } } ParseRelation(ParseObject parent, String key);   ParseRelation(String targetClass);   ParseRelation(JSONObject jsonObject, ParseDecoder decoder);   ParseRelation(Parcel source, ParseParcelDecoder decoder); void add(T object); void remove(T object); ParseQuery<T> getQuery(); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); final static Creator<ParseRelation> CREATOR; }