RestKit 警告:“发现一个仅包含 NSNull 值的集合...”

发布于 2024-11-29 14:42:26 字数 1927 浏览 1 评论 0原文

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

I have a RestKit-based app with one mapped class. Everything seems to work fine. However, when I retrieve objects, RestKit emits a warning:

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

The warning appears twice (presumably because there are two objects in JSON response). How can I fix that?

Here's my mapping:

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"];

Here's how I retrieve objects:

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

Here's my JSON structure (retrieved via 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
    }
  }
]

The server is Rails 3.0 app which I control and can modify response format if needed.

I'm using RestKit 0.9.3.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

内心旳酸楚 2024-12-06 14:42:27

此警告并不表示映射不正确。事实上,此消息可能应该记录为“调试”或“跟踪”,因为它可能作为正常对象映射的一部分出现。我将提交拉取请求以更改将来的日志级别。因此,请放心,您的映射没有问题,无需进行任何更改即可消除此警告。 :)

This warning is not a sign of an improper mapping. In fact this message should probably be logged as Debug or Trace as it can occur as part of normal object mapping. I'll submit a pull request to change the log level for the future. So rest assured your mapping is fine and no changes are necessary to quiet this warning. :)

缪败 2024-12-06 14:42:27

在最近安装的 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...");

Still getting this warning on the recently installed RestKit, made the following change in the RestKit code.

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

changed:

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

to:

RKLogDebug(@"Found a collection containing only NSNull values, considering the collection unmappable...");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文