Parse NSDictionary in ObjectMapper.

Summary: Some objects returned from sqlite in json blob is a NSDictionary, we need to parse data at this case.

Differential Revision: D48394361

fbshipit-source-id: c977ebdd33c392fca77741cdacdeb0c975e2ca36
This commit is contained in:
Fúlvio Abrahão de Paula
2023-08-17 11:19:50 -07:00
committed by Facebook GitHub Bot
parent b45eed0e9a
commit fb47b70d36

View File

@@ -151,6 +151,25 @@ static NSString* const UNKNOWN_BLOB_LABEL_FORMAT = @"{%d-byte %@ blob}";
} else if ([object isKindOfClass:[NSData class]]) { } else if ([object isKindOfClass:[NSData class]]) {
NSString* blobString = [self blobToString:(NSData*)object]; NSString* blobString = [self blobToString:(NSData*)object];
return @{@"type" : @"blob", @"value" : blobString}; return @{@"type" : @"blob", @"value" : blobString};
} else if ([object isKindOfClass:[NSDictionary class]]) {
// Usualy the dictionary is a Json blob, and we can parse it as string.
NSError* error;
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:object
options:0
error:&error];
if (!jsonData) {
NSString* reason = [NSString
stringWithFormat:@"NSDictionary is not in a json format: %@",
[error localizedDescription]];
@throw [NSException exceptionWithName:@"InvalidArgumentException"
reason:reason
userInfo:nil];
}
NSString* jsonString = [[NSString alloc] initWithData:jsonData
encoding:NSUTF8StringEncoding];
return @{@"type" : @"blob", @"value" : jsonString};
} else if ([object isKindOfClass:[NSValue class]]) { } else if ([object isKindOfClass:[NSValue class]]) {
return @{@"type" : @"boolean", @"value" : object}; return @{@"type" : @"boolean", @"value" : object};
} else { } else {