@@ -559,6 +559,20 @@ static id SEGCoerceJSONObject(id obj)
559
559
}
560
560
561
561
562
+ @implementation NSJSONSerialization (Serializable)
563
+ + (BOOL )isOfSerializableType : (id )obj
564
+ {
565
+ if ([obj isKindOfClass: [NSArray class ]] ||
566
+ [obj isKindOfClass: [NSDictionary class ]] ||
567
+ [obj isKindOfClass: [NSString class ]] ||
568
+ [obj isKindOfClass: [NSNumber class ]] ||
569
+ [obj isKindOfClass: [NSNull class ]])
570
+ return YES ;
571
+ return NO ;
572
+ }
573
+ @end
574
+
575
+
562
576
@implementation NSDictionary (SerializableDeepCopy)
563
577
564
578
- (id )serializableDeepCopy : (BOOL )mutable
@@ -569,11 +583,12 @@ - (id)serializableDeepCopy:(BOOL)mutable
569
583
id aValue = [self objectForKey: key];
570
584
id theCopy = nil ;
571
585
572
- if (![aValue conformsToProtocol: @protocol (NSCoding)]) {
586
+ if (![NSJSONSerialization isOfSerializableType: aValue]) {
587
+ NSString *className = NSStringFromClass ([aValue class ]);
573
588
#ifdef DEBUG
574
- NSAssert (FALSE , @" key `%@ ` doesn't conform to NSCoding and can't be serialized for delivery." , key);
589
+ NSAssert (FALSE , @" key `%@ ` is a %@ and can't be serialized for delivery." , key, className );
575
590
#else
576
- SEGLog (@" key `%@ ` doesn't conform to NSCoding and can't be serialized for delivery." , key);
591
+ SEGLog (@" key `%@ ` is a %@ and can't be serializaed for delivery." , key, className );
577
592
// simply leave it out since we can't encode it anyway.
578
593
continue ;
579
594
#endif
@@ -617,16 +632,17 @@ -(id)serializableDeepCopy:(BOOL)mutable
617
632
for (id aValue in self) {
618
633
id theCopy = nil ;
619
634
620
- if (![aValue conformsToProtocol: @protocol (NSCoding)]) {
635
+ if (![NSJSONSerialization isOfSerializableType: aValue]) {
636
+ NSString *className = NSStringFromClass ([aValue class ]);
621
637
#ifdef DEBUG
622
- NSAssert (FALSE , @" type ` %@ ` doesn't conform to NSCoding and can't be serialized for delivery." , NSStringFromClass ([aValue class ]) );
638
+ NSAssert (FALSE , @" found a %@ which can't be serialized for delivery." , className );
623
639
#else
624
- SEGLog (@" type ` %@ ` doesn't conform to NSCoding and can't be serialized for delivery." , NSStringFromClass ([aValue class ]) );
640
+ SEGLog (@" found a %@ which can't be serializaed for delivery." , className );
625
641
// simply leave it out since we can't encode it anyway.
626
642
continue ;
627
643
#endif
628
644
}
629
-
645
+
630
646
if ([aValue conformsToProtocol: @protocol (SEGSerializableDeepCopy)]) {
631
647
theCopy = [aValue serializableDeepCopy: mutable];
632
648
} else if ([aValue conformsToProtocol: @protocol (NSCopying)]) {
0 commit comments