Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Parse/Parse/Source/PFDecoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,28 @@ - (id)decodeDictionary:(NSDictionary *)dictionary {
}

NSString *type = dictionary[@"__type"];
// Inject __type = @"Object" if missing but className/objectId present and on the presence of additional data fields so that bare pointer stubs continue to fall back to the legacy dictionary path.
if (!type && dictionary[@"className"] && dictionary[@"objectId"]) {
static NSSet<NSString *> *pointerKeys;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
pointerKeys = [NSSet setWithObjects:@"className", @"objectId", @"localId", nil];
});
BOOL hasAdditionalFields = NO;
for (NSString *key in dictionary) {
if (![pointerKeys containsObject:key]) {
hasAdditionalFields = YES;
break;
}
}
if (!hasAdditionalFields) {
return dictionary;
}
NSMutableDictionary *mutable = [dictionary mutableCopy];
mutable[@"__type"] = @"Object";
type = @"Object";
dictionary = mutable;
}
if (type) {
if ([type isEqualToString:@"Date"]) {
return [[PFDateFormatter sharedFormatter] dateFromString:dictionary[@"iso"]];
Expand Down
1 change: 0 additions & 1 deletion ParseLiveQuery/ParseLiveQuery/Internal/ClientPrivate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ private func parseObject<T: PFObject>(_ objectDictionary: [String:AnyObject]) th
guard let _ = objectDictionary["objectId"] as? String else {
throw LiveQueryErrors.InvalidJSONError(json: objectDictionary, expectedKey: "objectId")
}

guard let object = PFDecoder.object().decode(objectDictionary) as? T else {
throw LiveQueryErrors.InvalidJSONObject(json: objectDictionary, details: "cannot decode json into \(T.self)")
}
Expand Down