6

我有一个基于 RestKit 的应用程序,其中包含一个映射类。一切似乎都很好。但是,当我检索对象时,RestKit 会发出警告:

W restkit.object_mapping:RKObjectMapper.m:90 Found a collection containing only NSNull values, considering the collection unmappable...

警告出现两次(可能是因为 JSON 响应中有两个对象)。我该如何解决?

这是我的映射:

RKManagedObjectMapping* presentationMapping = [RKManagedObjectMapping mappingForClass:[Presentation class]];
presentationMapping.primaryKeyAttribute = @"presentationId";
[presentationMapping mapKeyPath:@"id" toAttribute:@"presentationId"];
[presentationMapping mapKeyPath:@"title" toAttribute:@"title"];
[presentationMapping mapKeyPath:@"description" toAttribute:@"descriptionText"];
[presentationMapping mapKeyPath:@"download_url" toAttribute:@"downloadUrlString"];
[presentationMapping mapKeyPath:@"download_file_size" toAttribute:@"downloadFileSize"];

[objectManager.mappingProvider setMapping:presentationMapping forKeyPath:@"presentation"];

这是我检索对象的方法:

[[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"/presentations" delegate:self];

这是我的 JSON 结构(通过 curl 检索):

[
  {
    "presentation": {
      "created_at":"2011-08-13T17:09:40+02:00",
      "description":"Lorem ipsum",
      "id":1,
      "title":"Xxx",
      "updated_at":"2011-08-13T17:09:40+02:00",
      "download_url":"http://xxx.example.com/system/downloads/1/original/presentation1.zip?1313248180",
      "download_file_size":171703
    }
  },
  {
    "presentation": {
      "created_at":"2011-08-13T17:10:30+02:00",
      "description":"Dolor sit amet",
      "id":2,
      "title":"Zzz",
      "updated_at":"2011-08-15T00:22:10+02:00",
      "download_url":"http://xxx.example.com/system/downloads/2/original/zzz.zip?1313360530",
      "download_file_size":3182117
    }
  }
]

服务器是我控制的 Rails 3.0 应用程序,可以根据需要修改响应格式。

我正在使用 RestKit 0.9.3。

4

2 回答 2

1

此警告并不表示映射不正确。事实上,这条消息可能应该被记录为 Debug 或 Trace,因为它可以作为正常对象映射的一部分出现。我将提交一个拉取请求以更改未来的日志级别。所以请放心,您的映射很好,无需更改即可消除此警告。:)

于 2011-08-15T13:32:34.100 回答
0

在最近安装的 RestKit 上仍然收到此警告,对 RestKit 代码进行了以下更改。

FILE: RKPbjectMapper.m 
FUNCTION: (BOOL)isNullCollection:(id)object
LINE: 104

改变:

RKLogWarning(@"Found a collection containing only NSNull values, considering the collection unmappable...");

到:

RKLogDebug(@"Found a collection containing only NSNull values, considering the collection unmappable...");
于 2011-11-09T16:02:08.030 回答