Restkit is mapping my date just fine to an object, but when trying to do an inverse mapping back to json i'm getting this error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Invalid type in JSON write (__NSDate)'
Obviously this is an issue with the json parser for iOS, but I figured the inverse should be handled by RestKit as well. Anyone else experience this or have a solution?
In logging restkit I get this message right before:
D restkit.object_mapping:RKMappingOperation.m:920 Finished mapping operation successfully...
**EDIT:
Mapping example:
// Define media mapping
RKObjectMapping *mediaMapping = [Media getObjectMapping];
// Define Post mapping
RKObjectMapping *postMapping = [RKObjectMapping mappingForClass:[self class]];
[postMapping addAttributeMappingsFromDictionary:@{
@"post_id": @"postID",
@"userID": @"userID",
@"title": @"title",
@"favorite": @"favorite",
@"created": @"created",
@"modified": @"modified"}];
// Define relationship in the mapping between Media and Post
[postMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"media"
toKeyPath:@"media"
withMapping:mediaMapping]];
Discriptor example:
RKObjectMapping *entityMapping = [object getObjectMapping];
RKResponseDescriptor *successDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:entityMapping
method:RKRequestMethodPOST
pathPattern:request.URL.relativePath
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
**UPDATE2:
Right from the dictionary I break point and inspected the offending value in the destination object.
[11] = @"created" : 2014-04-21 11:04:43 PDT
key __NSCFConstantString * @"created" 0x002d3818
value __NSDate * 2014-04-21 11:04:43 PDT 0x155bab10
I can see the issue, it appears to be passing the dictionary with the NSDate to [NSJSONSerialization dataWithJSONObject: options: error:] via this method, [RKSerialization dataFromObject: error;
Should RestKit not be converting the NSDate using the RKValueTransformer I have defined before passing to NSJSONSerialization?
Open issue at github can be found here.