@@ -61,13 +61,30 @@ static CFNumberType PFNumberTypeForObjCType(const char *encodedType) {
6161 [' f' ] = kCFNumberFloatType ,
6262 [' d' ] = kCFNumberDoubleType ,
6363
64- // C99 & CXX boolean
64+ // C99 & CXX boolean. We are keeping this here for decoding, as you can safely use CFNumberGetBytes on a
65+ // CFBoolean, and extract it into a char.
6566 [' B' ] = kCFNumberCharType ,
6667 };
6768
6869 return (CFNumberType)types[encodedType[0 ]];
6970}
7071
72+ static NSNumber *PFNumberCreateSafe (const char *typeEncoding, const void *bytes) {
73+ // NOTE: This is required because NSJSONSerialization treats all NSNumbers with the 'char' type as numbers, not
74+ // booleans. As such, we must treat any and all boolean type encodings as explicit booleans, otherwise we will
75+ // send '1' and '0' to the api server rather than 'true' and 'false'.
76+ //
77+ // TODO (richardross): When we drop support for 10.9/iOS 7, remove the 'c' encoding and only use the new 'B'
78+ // encoding.
79+ if (typeEncoding[0 ] == ' B' || typeEncoding[0 ] == ' c' ) {
80+ return [NSNumber numberWithBool: *(BOOL *)bytes];
81+ }
82+
83+ CFNumberType numberType = PFNumberTypeForObjCType (typeEncoding);
84+ PFConsistencyAssert (numberType != kCFNumberTypeUnknown , @" Unsupported type encoding %s !" , typeEncoding);
85+ return (__bridge_transfer NSNumber *)CFNumberCreate (NULL , numberType, bytes);
86+ }
87+
7188@implementation PFObjectSubclassingController {
7289 dispatch_queue_t _registeredSubclassesAccessQueue;
7390 NSMutableDictionary *_registeredSubclasses;
@@ -230,11 +247,7 @@ - (void)_forwardSetterInvocation:(NSInvocation *)invocation
230247 dictionaryValue = [dictionaryValue copy ];
231248 }
232249 } else {
233- CFNumberType numberType = PFNumberTypeForObjCType (argumentType);
234- PFConsistencyAssert (numberType != kCFNumberTypeUnknown , @" Unsupported type encoding %s !" , argumentType);
235-
236- CFNumberRef number = CFNumberCreate (NULL , numberType, argumentValueBytes);
237- dictionaryValue = (__bridge_transfer id )number;
250+ dictionaryValue = PFNumberCreateSafe (argumentType, argumentValueBytes);
238251 }
239252
240253 if (dictionaryValue == nil ) {
0 commit comments