RestKit不是逆映射日期

时间:2013-12-06 20:28:45

标签: json restkit restkit-0.20

Restkit将我的日期很好地映射到一个对象,但是当我尝试将反向映射回到json时,我收到了这个错误:

    *** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
    reason: 'Invalid type in JSON write (__NSDate)'

显然这是iOS的json解析器的问题,但我认为逆也应该由RestKit处理。有其他人经历过这个或有解决方案吗?

在记录restkit时,我之前收到此消息:

D restkit.object_mapping:RKMappingOperation.m:920 Finished mapping operation successfully...

**编辑:

映射示例:

// 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示例:

RKObjectMapping *entityMapping = [object getObjectMapping];

RKResponseDescriptor *successDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:entityMapping
                                                                                        method:RKRequestMethodPOST
                                                                                   pathPattern:request.URL.relativePath
                                                                                       keyPath:nil
                                                                                   statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

** UPDATE2:

从词典中我断点并检查目标对象中的违规值。 [11] = @“创建”:2014-04-21 11:04:43 PDT
key __NSCFConstantString * @“created”0x002d3818 值__NSDate * 2014-04-21 11:04:43 PDT 0x155bab10

我可以看到这个问题,它似乎是通过这个方法将带有NSDate的字典传递给[NSJSONSerialization dataWithJSONObject:options:error:],[RKSerialization dataFromObject:error;

RestKit是否应该使用我在传递给NSJSONSerialization之前定义的RKValueTransformer来转换NSDate?

github上的开放问题可以找到here

0 个答案:

没有答案