I've looking for an answer for hours, I have no ideia what to do.
I have a JSON that I need to map, which has an array of string with no keyPath, but also has an attribute that needed to be mapped which has a keyPath. I was using RestKit 0.21.0, and had the same error when I updated to RestKit 0.22.0.
JSON:
{
"content": {
"site": "www.inf.ufsc.br/~fcdocil",
"modulos": [
"noticias",
"fotos",
"conteudo"
]
}
}
RKResponseDescriptor:
RKEntityMapping *moduleMapping = [RKEntityMapping mappingForEntityForName:@"Module" inManagedObjectStore:store];
[moduleMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"type"]];
[moduleMapping addAttributeMappingsFromDictionary:@{@"@parent.site" : @"site"}];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:moduleMapping method:RKRequestMethodAny pathPattern:nil keyPath:@"content.modulos" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
When I run this, it successful map the array in 3 different element, as you can see here:
SUCCESS (
"<Module: 0x8e54280> (entity: Module; id: 0x8cd31f0 <x-coredata://B31664A2-091E-43B8-9B36-EB7AF6C27292/Module/p4> ; data: {\n site = nil;\n type = noticias;\n})",
"<Module: 0x8e666b0> (entity: Module; id: 0x8cd3180 <x-coredata://B31664A2-091E-43B8-9B36-EB7AF6C27292/Module/p2> ; data: {\n site = nil;\n type = fotos;\n})",
"<Module: 0x8e66a60> (entity: Module; id: 0x8cd3170 <x-coredata://B31664A2-091E-43B8-9B36-EB7AF6C27292/Module/p3> ; data: {\n site = nil;\n type = conteudo;\n})"
)
But It didn't do the @parent.site
, which I desire is:
SUCCESS (
"<Module: 0x8e54280> (entity: Module; id: 0x8cd31f0 <x-coredata://B31664A2-091E-43B8-9B36-EB7AF6C27292/Module/p4> ; data: {\n site = www.inf.ufsc.br/~fcdocil;\n type = noticias;\n})",
"<Module: 0x8e666b0> (entity: Module; id: 0x8cd3180 <x-coredata://B31664A2-091E-43B8-9B36-EB7AF6C27292/Module/p2> ; data: {\n site = www.inf.ufsc.br/~fcdocil;\n type = fotos;\n})",
"<Module: 0x8e66a60> (entity: Module; id: 0x8cd3170 <x-coredata://B31664A2-091E-43B8-9B36-EB7AF6C27292/Module/p3> ; data: {\n site = www.inf.ufsc.br/~fcdocil;\n type = conteudo;\n})"
)
I'm using CoreData to save the data, and my ManagedObject is like that,
Module.h
@interface Module : NSManagedObject
@property (nonatomic, retain) NSString * type;
@property (nonatomic, retain) NSString * site;
@end
Module.m
@implementation Module
@dynamic type;
@dynamic site;
@end
I really have no ideia what I'm doing wrong, so any suggestions would be appreciated. Thanks