我正在使用RestKit 0.20并在使用带点(。)的规范符号时检测到一种奇怪的映射行为。我很高兴,如果你能解释一个简单的方法来处理从我在IOS上实现为NSManagedObject的扁平对象到服务器端的对象关系的对象映射。
映射几乎是正确的,但是根据我的观点,将geopoint.lat和geopoint.lon映射为额外字段是错误的,并在服务器上引发异常(无法识别的属性异常)。
RKObjectMapping:
[mapping addAttributeMappingsFromDictionary:@{
@"geopoint.lat": @"latitude",
@"geopoint.lon": @"longitude",
@"countrycode": @"countryId",
@"county": @"county",
@"postcode": @"postalcode",
@"city": @"city",
@"street": @"street",
@"housenumber": @"housenumber"
}];
有效结果(显示为日志输出)
2013-01-29 09:29:38.856 CPlusApp[4285:907] T restkit.object_mapping:RKMappingOperation.m:514 Mapped relationship object from keyPath 'startAddress' to 'startAddress'. Value: {
city = aCity;
geopoint = {
lat = "48.8901234";
lon = "8.818448999999998976";
};
"geopoint.lat" = "48.8901234";
"geopoint.lon" = "8.818448999999998976";
postcode = 91000;
street = Rennbrunnen;
}
2013-01-29 09:29:38.861 CPlusApp[4285:907] D restkit.object_mapping:RKMappingOperation.m:818 Finished mapping operation successfully...
答案 0 :(得分:0)
我一直处于类似情况,我可以看到两种解决方案:
1)为具有lat和lon属性的geopoint创建一个新类。然后在对象的类中添加geopoint
作为属性。从字典中删除两个映射(geopoint.lat& geopoint.lon)并添加从keyPath'lossoint'到'geopoint'的关系。从那时起,您可以通过object.geopoint.lat
和object.geopoint.lon
访问纬度和经度。
2)通过以下内容删除请求的映射:
RKEntityMapping *addressRequestMapping = [mapping inverseMapping];
[addressRequestMapping removePropertyMapping:[addressRequestMapping propertyMappingsBySourceKeyPath][@"geopoint.lat"]];
[addressRequestMapping removePropertyMapping:[addressRequestMapping propertyMappingsBySourceKeyPath][@"geopoint.lon"]];
[manager addRequestDescriptorsFromArray:@[
[RKRequestDescriptor addressRequestMapping objectClass:[Address class] rootKeyPath:nil]
]];
选项1允许您修改坐标并将数据PUT到服务器,而选项2则不会。