如何将扁平对象序列化回服务器,在 RestKit 中未扁平化 [英] How to serialize a flattened object back to server, unflattened in RestKit
问题描述
使用 RestKit 0.10.1,我提供了类似于这种 json 格式的对象:
Using RestKit 0.10.1, I have objects served similar to this json format:
{"objects": [
{"owner": 1,
"_id": 823,
"data": {
"diam": 5.0,
"plant_date": "10/02/2008"}
},
... ] }
在客户端,我不需要子对象或关系,所以我扁平化到我的对象的属性:
on the client side, I do not need to have sub objects or relationships, so I flatten to attributes of my object:
[myMapping mapKeyPathsToAttibutes:
@"_id", @"id",
@"owner", @"owner",
@"data.diam", @"diam", //here is what I mean by flatten; notice data.diam -> diam
@"data.plant_date", @"plant_date", nil];
我读取这些数据没有问题,但是当我想序列化它时,只有顶级属性会被发送到服务器.当我序列化时,这是服务器得到的:
I have no problem reading this data, but when I want to serialize it, only the top-level attributes get sent to the server. When I serialize, here is what the server gets:
{"_id":0,"owner":1}
请注意,我已正确(我认为)使用上述的 inverseMapping 注册了序列化映射:
Note that I have correctly (I think) registered the Serialization mapping with an inverseMapping of the above:
[objectManager.mappingProvider setSerializationMapping:[myMapping inverseMapping] forClass:[MyClass class]];
何时我像这样发布对象:
myObject = [MyClass object];
myObject.diam = [NSNumber numberWithInt:5];
myObject.plant_date = myDate;
[[RKObjectManager sharedManager] postObject:myObject delegate:self];
我希望拥有完整的、未扁平化的结构:
I would like to have the complete, unflattened structure:
{"_id":0,"owner":1, "data": {"diam": 5.0, "plant_date": "10/02/2008"} }
如何使用 RestKit 实现将注册对象映射到服务器的键路径(即data.diam")发布?
How can I achieve posting a keypath (i.e. "data.diam") mapping registered object to server using RestKit?
推荐答案
请注意,此错误已在 RestKit 中修复,并在 0.20 中发布.请参阅变更集@https://github.com/RestKit/RestKit/commit/66d9073d98c88c88c85c88c8c88c88c88c88c8c88c8c88c8c88c88c88c8c98c88c8c98c8c98c9f663fc998bbe738945e9bbe738945e9
Note that this bug has been fixed in RestKit on the development for release in 0.20. See the changeset @ https://github.com/RestKit/RestKit/commit/64e9c7cb6d04dd8750e9f663fc998bbe738945e9
这篇关于如何将扁平对象序列化回服务器,在 RestKit 中未扁平化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!