RestKit/RestKit — Issue #514: NSorderedSet cannot be serialized to JSON
Author: lightforce
Created: 2012-01-20 19:04:26+00:00
State: open

Although NSOrderedSet can be mapped to an array thanks to https://github.com/RestKit/RestKit/pull/504, they cannot be serialized directly down to JSON. Steps to reproduce:

Setup:

@interface Item : NSManagedObject
@property (nonatomic, strong) NSNumber * entityID;
@property (nonatomic, strong) NSOrderedSet * otherItems;
@end

@interface Other : NSManagedObject
@property (nonatomic, strong) NSNumber * entityID;
@end

Mapping:

RKManagedObjectMapping* otherMapping = [RKManagedObjectMapping mappingForEntityWithName:@"Other"];
RKManagedObjectMapping* itemMapping = [RKManagedObjectMapping mappingForClass:[Item class]];
[itemMapping mapAttributes:@"entityID",@"multipleItems", nil];
[itemMapping mapRelationship:@"multipleItems" withMapping:otherMapping];

Posting an item:

[[RKObjectManager sharedManager] postObject:object delegate:self block:^(RKObjectLoader* loader) {
loader.objectMapping = [[RKObjectManager sharedManager].mappingProvider objectMappingForClass:[Item class]];
}];

Produces:

Unable to serialize object class __NSOrderedSetI