Nested RestKit Binding to a Specific Array Element

Is it possible to force the Mapper of a RestKit to map a specific nested object in an array using mapKeyPath syntax?

Here is the answer I'm trying to display

<result is_array="true">
  <item>
     <_field_data>
        <nid>
           <entity>
              <field_region>
                 <und is_array="true">
                    <item>
                       <value>1</value>
                    </item>
                 </und>
              </field_region>
....

I'm only interested in the first element that will ever be returned for field_region.

What is the correct way to match this?

I tried various iterations:

RKManagedObjectMapping *record = [RKManagedObjectMapping mappingForClass:[MyRecordClass class] inManagedObjectStore:objManager.objectStore];
[record mapKeyPath:@"_field_data.nid.entity.field_region.und.0.item.value" toAttribute:@"region"];

and I keep getting errors similar to:

T restkit.object_mapping:RKObjectMappingOperation.m:152 Found transformable value at keyPath '_field_data.nid.entity.field_region.und.0.item.value'. Transforming from type '__NSArrayI' to 'NSNumber'
W restkit.object_mapping:RKObjectMappingOperation.m:232 Failed transformation of value at keyPath '_field_data.nid.entity.field_region.und.0.item.value'. No strategy for transforming from '__NSArrayI' to 'NSNumber'

I invoke the mapping through:

[[RKObjectManager sharedManager] loadObjectsAtResourcePath:kMyResourcePath usingBlock:^(RKObjectLoader* loader) {
    loader.objectMapping = [[RKObjectManager sharedManager].mappingProvider objectMappingForClass:[MyRecordClass class]];
    loader.method = RKRequestMethodGET;
    loader.delegate = self;
    loader.targetObject = nil;
}];

Any ideas? Most valuable!

+5
source share
1 answer

Think that you need to have a mapping for each level, so the display of an object object contains a field region object. the display of an area object of an area contains an object und. und object mapping contains an element, etc.

json, xml, .

- ( , )

RKObjectMapping* undMapping = [RKObjectMapping mappingForClass:[UND class]];
[und mapKeyPath:@"item" toAttribute:@"item"];

RKObjectMapping* regionmapping = [RKObjectMapping mappingForClass:[Region class]]; 
[regionmapping mapKeyPath:@"und" toRelationship:@"undArrays" withMapping:undMapping];
0

All Articles