My app creates some ObJC objects from JSON. Things were working fine, until I added a new property to my ObjC model class, which doesn't have a counterpart in JSON.
I've configured the mapping as follows:
+ (NSDictionary *)JSONKeyPathsByPropertyKey
{
return @{
@"firstName" : @"firstname",
@"middleName" : @"middlename",
@"lastName" : @"lastname",
// etc.
@"phoneNumber" : NSNull.null // no JSON data for this one
};
}
However I get an assertion failure in Mantle, in MTLJSONAdapter initWithModelClass
: "phoneNumber must either map to a JSON key path or a JSON array of key paths, got: null."
This is how I create the model object:
MyData *myData = [MTLJSONAdapter modelOfClass:[MyData class]
fromJSONDictionary:json error:&error];
How can I have the phoneNumber
property in the data class without it mapping to a JSON value?
Just don't specify its mapping to + JSONKeyPathsByPropertyKey
.