Skip to content
This repository was archived by the owner on Sep 26, 2025. It is now read-only.

Commit fb47b70

Browse files
fulvioabrahaofacebook-github-bot
authored andcommitted
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
1 parent b45eed0 commit fb47b70

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

  • iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin

iOS/Plugins/FlipperKitDatabasesPlugin/FlipperKitDatabasesPlugin/ObjectMapper.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,25 @@ + (NSDictionary*)objectAndTypeToFlipperObject:(id)object {
151151
} else if ([object isKindOfClass:[NSData class]]) {
152152
NSString* blobString = [self blobToString:(NSData*)object];
153153
return @{@"type" : @"blob", @"value" : blobString};
154+
} else if ([object isKindOfClass:[NSDictionary class]]) {
155+
// Usualy the dictionary is a Json blob, and we can parse it as string.
156+
NSError* error;
157+
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:object
158+
options:0
159+
error:&error];
160+
if (!jsonData) {
161+
NSString* reason = [NSString
162+
stringWithFormat:@"NSDictionary is not in a json format: %@",
163+
[error localizedDescription]];
164+
@throw [NSException exceptionWithName:@"InvalidArgumentException"
165+
reason:reason
166+
userInfo:nil];
167+
}
168+
169+
NSString* jsonString = [[NSString alloc] initWithData:jsonData
170+
encoding:NSUTF8StringEncoding];
171+
return @{@"type" : @"blob", @"value" : jsonString};
172+
154173
} else if ([object isKindOfClass:[NSValue class]]) {
155174
return @{@"type" : @"boolean", @"value" : object};
156175
} else {

0 commit comments

Comments
 (0)