Skip to content

Commit 07b9c62

Browse files
committed
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.
1 parent eeebc5b commit 07b9c62

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

Parse/Parse/Source/PFDecoder.m

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,28 @@ - (id)decodeDictionary:(NSDictionary *)dictionary {
4747
}
4848

4949
NSString *type = dictionary[@"__type"];
50-
// Inject __type = @"Object" if missing but className/objectId present
50+
// 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.
5151
if (!type && dictionary[@"className"] && dictionary[@"objectId"]) {
52-
NSMutableDictionary *mutable = [dictionary mutableCopy];
53-
mutable[@"__type"] = @"Object";
54-
type = @"Object";
55-
dictionary = mutable;
56-
}
52+
static NSSet<NSString *> *pointerKeys;
53+
static dispatch_once_t onceToken;
54+
dispatch_once(&onceToken, ^{
55+
pointerKeys = [NSSet setWithObjects:@"className", @"objectId", @"localId", nil];
56+
});
57+
BOOL hasAdditionalFields = NO;
58+
for (NSString *key in dictionary) {
59+
if (![pointerKeys containsObject:key]) {
60+
hasAdditionalFields = YES;
61+
break;
62+
}
63+
}
64+
if (!hasAdditionalFields) {
65+
return dictionary;
66+
}
67+
NSMutableDictionary *mutable = [dictionary mutableCopy];
68+
mutable[@"__type"] = @"Object";
69+
type = @"Object";
70+
dictionary = mutable;
71+
}
5772
if (type) {
5873
if ([type isEqualToString:@"Date"]) {
5974
return [[PFDateFormatter sharedFormatter] dateFromString:dictionary[@"iso"]];

0 commit comments

Comments
 (0)