I am getting a json document like this from a ws:
{
...
error=true,
errorMsg="xyz",
errorCode="1234"
}
But these attributes are optional so sometimes they are present and sometime they are not.
I added a dynamic mapping for reading only error - only if error is set to true
either:
[dynamicMapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"error" expectedValue:[NSNumber numberWithInt:1] objectMapping:errorMapping]];
or
[dynamicMapping setObjectMappingForRepresentationBlock:^RKObjectMapping *(id representation) {
if ([[representation valueForKey:@"error"] isEqualToNumber:[NSNumber numberWithInt:1]]) {
return errorMapping;
}
return nil;
}];
Everything is working fine if error=true but if the error attributes are missing I get a warning:
restkit.object_mapping:RKMapperOperation.m:98 Adding mapping error: Could not find an object mapping for keyPath: '<null>'
I just want to get rid of the warning. What is the best practice for this problem? How do I mark the attribute as optional?