Skip to content

Commit eeebc5b

Browse files
committed
LiveryQuery server response sends data or events in "object":jsonf= format but PFDecoder.m checks for __type key which is missing as shown in below example so this fix will add "__type ":"Object" key-value if dictionary has className and objectId representing PFObject.
"object":{ "desc": "Technology", "createdAt": "2020-10-03T19:34:16.823Z", "updatedAt": "2025-09-27T17:55:02.360Z", "image_name": "technology.png", "className": "categories", "objectId": "kHnBntWHHW" }, "original": { "desc": "Technologyy", "createdAt": "2020-10-03T19:34:16.823Z", "updatedAt": "2025-09-27T17:54:10.800Z", "image_name": "technology.png", "className": "categories", "objectId": "kHnBntWHHW" }
1 parent 18003b0 commit eeebc5b

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

Parse/Parse/Source/PFDecoder.m

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

4949
NSString *type = dictionary[@"__type"];
50+
// Inject __type = @"Object" if missing but className/objectId present
51+
if (!type && dictionary[@"className"] && dictionary[@"objectId"]) {
52+
NSMutableDictionary *mutable = [dictionary mutableCopy];
53+
mutable[@"__type"] = @"Object";
54+
type = @"Object";
55+
dictionary = mutable;
56+
}
5057
if (type) {
5158
if ([type isEqualToString:@"Date"]) {
5259
return [[PFDateFormatter sharedFormatter] dateFromString:dictionary[@"iso"]];

ParseLiveQuery/ParseLiveQuery/Internal/ClientPrivate.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ private func parseObject<T: PFObject>(_ objectDictionary: [String:AnyObject]) th
1818
guard let _ = objectDictionary["objectId"] as? String else {
1919
throw LiveQueryErrors.InvalidJSONError(json: objectDictionary, expectedKey: "objectId")
2020
}
21-
22-
//workaround to fix missing __type key Decoder expects with value "Object"
23-
var dict = objectDictionary
24-
dict["__type"] = String("Object") as AnyObject
25-
guard let object = PFDecoder.object().decode(dict) as? T else {
21+
guard let object = PFDecoder.object().decode(objectDictionary) as? T else {
2622
throw LiveQueryErrors.InvalidJSONObject(json: objectDictionary, details: "cannot decode json into \(T.self)")
2723
}
2824

0 commit comments

Comments
 (0)