RestKit警告:“找到一个只包含NSNull值的集合......”

时间:2011-08-15 11:07:32

标签: objective-c restkit

我有一个基于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。

2 个答案:

答案 0 :(得分:1)

此警告不表示映射不正确。事实上,此消息应该记录为Debug或Trace,因为它可以作为普通对象映射的一部分发生。我将提交一个pull请求来更改将来的日志级别。所以请放心,你的映射很好,不需要修改这个警告。 :)

答案 1 :(得分: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...");
相关问题