diff --git a/JSONModel/JSONModel/JSONModel.m b/JSONModel/JSONModel/JSONModel.m index 1953da15..88320115 100644 --- a/JSONModel/JSONModel/JSONModel.m +++ b/JSONModel/JSONModel/JSONModel.m @@ -791,7 +791,7 @@ -(id)__transform:(id)value forProperty:(JSONModelClassProperty*)property error:( } //built-in reverse transformations (export to JSON compliant objects) --(id)__reverseTransform:(id)value forProperty:(JSONModelClassProperty*)property +-(id)__reverseTransform:(id)value forProperty:(JSONModelClassProperty*)property forPropertyNames:(NSArray *)propertyNames { Class protocolClass = NSClassFromString(property.protocol); if (!protocolClass) return value; @@ -803,8 +803,8 @@ -(id)__reverseTransform:(id)value forProperty:(JSONModelClassProperty*)property if (property.type == [NSArray class] || property.type == [NSMutableArray class]) { NSMutableArray* tempArray = [NSMutableArray arrayWithCapacity: [(NSArray*)value count] ]; for (NSObject* model in (NSArray*)value) { - if ([model respondsToSelector:@selector(toDictionary)]) { - [tempArray addObject: [model toDictionary]]; + if ([model respondsToSelector:@selector(toDictionaryWithKeys:)]) { + [tempArray addObject: [model toDictionaryWithKeys:propertyNames]]; } else [tempArray addObject: model]; } @@ -816,7 +816,7 @@ -(id)__reverseTransform:(id)value forProperty:(JSONModelClassProperty*)property NSMutableDictionary* res = [NSMutableDictionary dictionary]; for (NSString* key in [(NSDictionary*)value allKeys]) { id model = value[key]; - [res setValue: [model toDictionary] forKey: key]; + [res setValue: [model toDictionaryWithKeys:propertyNames] forKey: key]; } return [NSDictionary dictionaryWithDictionary:res]; } @@ -984,7 +984,8 @@ -(NSDictionary*)toDictionaryWithKeys:(NSArray*)propertyNames if ([value isKindOfClass:JSONModelClass]) { //recurse models - value = [(JSONModel*)value toDictionary]; + //another model also have some property not used + value = [(JSONModel*)value toDictionaryWithKeys:propertyNames]; [tempDictionary setValue:value forKeyPath: keyPath]; //for clarity @@ -994,7 +995,7 @@ -(NSDictionary*)toDictionaryWithKeys:(NSArray*)propertyNames // 1) check for built-in transformation if (p.protocol) { - value = [self __reverseTransform:value forProperty:p]; + value = [self __reverseTransform:value forProperty:p forPropertyNames:propertyNames]; } // 2) check for standard types OR 2.1) primitives