krzysztofzablocki / PropertyMapper

Property mapping for Objective-C iOS apps.

Home Page:http://merowing.info

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crash when mapping null object to a primitive

nandodelauni opened this issue · comments

This test doesn't pass when trying to map a null object to, for example, an int:

        it(@"should handle NULL value for primitive value", ^{
          sourceDictionary = @{@"testValue" : [NSNull null]};
          mapping = @{@"testValue" : @"intNumber" };
          [[theBlock(^{
            testResult = [KZPropertyMapper mapValuesFrom:sourceDictionary toInstance:testObject usingMapping:mapping];
           }) shouldNot] raise];
           [[theValue(testResult) should] beTrue];
        });

Does it make any sense to fix this or it's just a bad approach and should use the library in other way?

Sorry for late reply, I've been traveling a lot last month.

It handles nulls when mapping to pointers, as for primitives let's say you have scenario like that, the question is:

  • Should it ignore the value and leave the old one, or should it set the value to 0?

In general you should be able to use boxing to handle this mapping and apply any answer you'd like https://github.com/krzysztofzablocki/KZPropertyMapper#expanding-boxing-capabilities