Skip to content

Commit dc142e9

Browse files
committed
Merge pull request jsonmodel#269 from dbachrach/master
Store property type information from most specific class instead of most generic class
2 parents 3ae7737 + fca85f8 commit dc142e9

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

JSONModel/JSONModel/JSONModel.m

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,15 +347,19 @@ -(BOOL)__importDictionary:(NSDictionary*)dict withKeyMapper:(JSONKeyMapper*)keyM
347347
if (property.type == nil && property.structName==nil) {
348348

349349
//generic setter
350-
[self setValue:jsonValue forKey: property.name];
350+
if (jsonValue != [self valueForKey:property.name]) {
351+
[self setValue:jsonValue forKey: property.name];
352+
}
351353

352354
//skip directly to the next key
353355
continue;
354356
}
355357

356358
// 0.5) handle nils
357359
if (isNull(jsonValue)) {
358-
[self setValue:nil forKey: property.name];
360+
if ([self valueForKey:property.name] != nil) {
361+
[self setValue:nil forKey: property.name];
362+
}
359363
continue;
360364
}
361365

@@ -378,7 +382,9 @@ -(BOOL)__importDictionary:(NSDictionary*)dict withKeyMapper:(JSONKeyMapper*)keyM
378382
}
379383
return NO;
380384
}
381-
[self setValue:value forKey: property.name];
385+
if (![value isEqual:[self valueForKey:property.name]]) {
386+
[self setValue:value forKey: property.name];
387+
}
382388

383389
//for clarity, does the same without continue
384390
continue;
@@ -410,7 +416,9 @@ -(BOOL)__importDictionary:(NSDictionary*)dict withKeyMapper:(JSONKeyMapper*)keyM
410416
}
411417

412418
//set the property value
413-
[self setValue:jsonValue forKey: property.name];
419+
if (![jsonValue isEqual:[self valueForKey:property.name]]) {
420+
[self setValue:jsonValue forKey: property.name];
421+
}
414422
continue;
415423
}
416424

@@ -460,7 +468,9 @@ -(BOOL)__importDictionary:(NSDictionary*)dict withKeyMapper:(JSONKeyMapper*)keyM
460468
jsonValue = [valueTransformer performSelector:selector withObject:jsonValue];
461469
#pragma clang diagnostic pop
462470

463-
[self setValue:jsonValue forKey: property.name];
471+
if (![jsonValue isEqual:[self valueForKey:property.name]]) {
472+
[self setValue:jsonValue forKey: property.name];
473+
}
464474

465475
} else {
466476

@@ -474,7 +484,9 @@ -(BOOL)__importDictionary:(NSDictionary*)dict withKeyMapper:(JSONKeyMapper*)keyM
474484

475485
} else {
476486
// 3.4) handle "all other" cases (if any)
477-
[self setValue:jsonValue forKey: property.name];
487+
if (![jsonValue isEqual:[self valueForKey:property.name]]) {
488+
[self setValue:jsonValue forKey: property.name];
489+
}
478490
}
479491
}
480492
}
@@ -670,7 +682,7 @@ -(void)__inspectProperties
670682
}
671683

672684
//add the property object to the temp index
673-
if (p) {
685+
if (p && ![propertyIndex objectForKey:p.name]) {
674686
[propertyIndex setValue:p forKey:p.name];
675687
}
676688
}

0 commit comments

Comments
 (0)