iosobjective-crestkitrestkit-0.20

Restkit fails to use appropriate Mapping


I am using Restkit 0.26.0 to map JSON with multiple layers and this key path causes trouble:

productColorImages:   [
{
id: 10,
productId: "232",
color: "green",
url: "exampleURL.com"
},
{
id: 11,
productId: "232",
color: "red",
url: "exampleURL.com"
},
{
id: 12,
productId: "232",
color: "blue",
url: "exampleURL.com"
}
],

My mapping

      RKObjectMapping *transferProductColorImageMapping = [RKObjectMapping mappingForClass:[TransferProductColorImage  class]];
[transferProductColorImageMapping addAttributeMappingsFromDictionary:@{     @"identifier" : @"id",
                                                                            @"URL" : @"URL",
                                                                            @"productId" : @"productId",
                                                                                 @"color" : @"color"

[getProductPageMapping addRelationshipMappingWithSourceKeyPath:@"productColorImages" mapping:transferProductColorImageMapping];

The destination class

@interface TransferProductColorImage : NSObject

@property (nonatomic) NSNumber * identifier; // Mapps to id  ;int 64

@property (nonatomic) NSString * URL;
@property (nonatomic) NSString * productId;
@property (nonatomic) NSString * color;

The problem is that the resulting Object is of the right class but the properties are not filled.

I searched in the logs and found this:

    2016-05-30 17:42:24.007 thebrandsapp[20697:7047455] T restkit.object_mapping:RKMappingOperation.m:1173 Performing mapping operation: <RKMappingOperation 0x7f9e3b9c11e0> for 'TransferProductColorImage' object. Mapping values from object {
    color = green;
    id = 10;
    productId = 232;
    url = "exampleURL.com";
} to object <TransferProductColorImage: 0x7f9e3b846d60> with object mapping (null)

On the Model Object the productColorImages is a NSArray:

@property (nonatomic) NSArray <TransferProductColorImage *> * productColorImages;

This is odd because. How does Restkit know what mapping to use if the mapping is null. Is there any reason why the object mapping could be set to null?

Update: I found that the identifier and the color property were mapped correctly it is, the identifier and the url are not mapped correctly.


Solution

  • I changed the URL property to be lowercase: "url" and mapped it exactly like I did before and it worked. It seems like the the all-caps property name threw RestKit of.

    I swooped identifier and id, now they map correctly as well.