/** * Gets the <code>ParseObject</code> another object points to. By default a new * object will be created. */ protected ParseObject decodePointer(String className, String objectId) { return ParseObject.createWithoutData(className, objectId); }
/* package for tests */ ParseObject getParent() { if (parent == null) { return null; } if (parent.get() == null) { return ParseObject.createWithoutData(parentClassName, parentObjectId); } return parent.get(); }
protected ParseObject decodePointer(Parcel source) { // By default, use createWithoutData. Overriden in subclass. return ParseObject.createWithoutData(source.readString(), source.readString()); }
@Override protected ParseObject decodePointer(Parcel source) { String className = source.readString(); String objectId = source.readString(); if (objects.containsKey(objectId)) { return objects.get(objectId); } // Should not happen if encoding was done through ParseObjectParcelEncoder. ParseObject object = ParseObject.createWithoutData(className, objectId); objects.put(objectId, object); return object; }
/** * Creates a reference to an existing {@code ParseObject} for use in creating associations between * {@code ParseObject}s. Calling {@link #isDataAvailable()} on this object will return * {@code false} until {@link #fetchIfNeeded()} or {@link #fetch()} has been called. No network * request will be made. * * @param subclass The {@code ParseObject} subclass to create. * @param objectId The object id for the referenced object. * @return A {@code ParseObject} without data. */ @SuppressWarnings({"unused", "unchecked"}) public static <T extends ParseObject> T createWithoutData(Class<T> subclass, String objectId) { return (T) createWithoutData(getSubclassingController().getClassName(subclass), objectId); }
/** * Method used by parse server webhooks implementation to convert raw JSON to Parse Object * <p> * Method is used by parse server webhooks implementation to create a * new {@code ParseObject} from the incoming json payload. The method is different from * {@link #fromJSON(JSONObject, String, ParseDecoder, Set)} ()} in that it calls * {@link #build(JSONObject, ParseDecoder)} which populates operation queue * rather then the server data from the incoming JSON, as at external server the incoming * JSON may not represent the actual server data. Also it handles * {@link ParseFieldOperations} separately. * * @param json The object's data. * @param decoder Delegate for knowing how to decode the values in the JSON. */ static <T extends ParseObject> T fromJSONPayload( JSONObject json, ParseDecoder decoder) { String className = json.optString(KEY_CLASS_NAME); if (className == null || ParseTextUtils.isEmpty(className)) { return null; } String objectId = json.optString(KEY_OBJECT_ID, null); @SuppressWarnings("unchecked") T object = (T) ParseObject.createWithoutData(className, objectId); object.build(json, decoder); return object; }
/** * Creates a new {@code ParseObject} based on data from the Parse server. * * @param json The object's data. It is assumed to be complete, unless the JSON has the * {@link #KEY_SELECTED_KEYS} key. * @param defaultClassName The className of the object, if none is in the JSON. * @param decoder Delegate for knowing how to decode the values in the JSON. */ public static <T extends ParseObject> T fromJSON(JSONObject json, String defaultClassName, ParseDecoder decoder) { String className = json.optString(KEY_CLASS_NAME, defaultClassName); if (className == null) { return null; } String objectId = json.optString(KEY_OBJECT_ID, null); boolean isComplete = !json.has(KEY_SELECTED_KEYS); @SuppressWarnings("unchecked") T object = (T) ParseObject.createWithoutData(className, objectId); State newState = object.mergeFromServer(object.getState(), json, decoder, isComplete); object.setState(newState); return object; }
cursor.close(); @SuppressWarnings("unchecked") T pointer = (T) ParseObject.createWithoutData(className, objectId);
static ParseObject createFromParcel(Parcel source, ParseParcelDecoder decoder) { String className = source.readString(); String objectId = source.readByte() == 1 ? source.readString() : null; // Create empty object (might be the same instance if LDS is enabled) // and pass to decoder before unparceling child objects in State ParseObject object = createWithoutData(className, objectId); if (decoder instanceof ParseObjectParcelDecoder) { ((ParseObjectParcelDecoder) decoder).addKnownObject(object); } State state = State.createFromParcel(source, decoder); object.setState(state); if (source.readByte() == 1) object.localId = source.readString(); if (source.readByte() == 1) object.isDeleted = true; // If object.ldsEnabledWhenParceling is true, we got this from OfflineStore. // There is no need to restore operations in that case. boolean restoreOperations = !object.ldsEnabledWhenParceling; ParseOperationSet set = ParseOperationSet.fromParcel(source, decoder); if (restoreOperations) { for (String key : set.keySet()) { ParseFieldOperation op = set.get(key); object.performOperation(key, op); // Update ops and estimatedData } } Bundle bundle = source.readBundle(ParseObject.class.getClassLoader()); object.onRestoreInstanceState(bundle); return object; }
String key = (String) keys.next(); JSONArray pointerArray = newPointers.getJSONArray(key); builder.put(key, ParseObject.createWithoutData(pointerArray.optString(0), pointerArray.optString(1)));
@Test public void testSubclassPointers() { Person flashPointer = (Person) ParseObject.createWithoutData("Person", "someFakeObjectId"); assertFalse(flashPointer.isDirty()); }
/** * Converts a {@code ParseObject.State} to a {@code ParseObject}. * * @param state The {@code ParseObject.State} to convert from. * @return A {@code ParseObject} instance. */ static <T extends ParseObject> T from(ParseObject.State state) { @SuppressWarnings("unchecked") T object = (T) ParseObject.createWithoutData(state.className(), state.objectId()); synchronized (object.mutex) { State newState; if (state.isComplete()) { newState = state; } else { newState = object.getState().newBuilder().apply(state).build(); } object.setState(newState); } return object; }
@Test public void testDirtyingConstructorsThrow() { ClassWithDirtyingConstructor dirtyObj = new ClassWithDirtyingConstructor(); assertTrue(dirtyObj.isDirty()); try { ParseObject.createWithoutData("ClassWithDirtyingConstructor", "someFakeObjectId"); fail("Should throw due to subclass with dirtying constructor"); } catch (IllegalStateException e) { // success } }
@Test public void testParcelable() { ParseObject object = ParseObject.createWithoutData("Test", "objectId"); object.isDeleted = true; object.put("long", 200L); ParseObject other = ParseObject.createWithoutData("Test", "otherId"); object.put("pointer", other); object.setACL(acl); ParseObject related = ParseObject.createWithoutData("RelatedClass", "relatedId"); ParseRelation<ParseObject> rel = new ParseRelation<>(object, "relation"); rel.add(related);