Skip to content

Update JSONModel.m#618

Open
sunwillshine wants to merge 1 commit intojsonmodel:masterfrom
sunwillshine:patch-1
Open

Update JSONModel.m#618
sunwillshine wants to merge 1 commit intojsonmodel:masterfrom
sunwillshine:patch-1

Conversation

@sunwillshine
Copy link

@sunwillshine sunwillshine commented May 11, 2018

Allowing the wrong type definition does not cause the entire parent node JSONModel to be nil. "// 1) check if property is itself a JSONModel" has the same conditions.

NSString* jsonData = @{@"person":{ @"name": @"joke", @"age": @18, @"desc": [NSNull null]}}; // from server response data

@interface MYJSONModel : JSONModel
@EnD
@implementation MYJSONModel

  • (BOOL)propertyIsOptional:(NSString *)propertyName {
    return YES;
    }
    @EnD

@interface PersonItem : MYJSONModel
@Property (nonatomic, copy) NSString* name;
@Property (nonatomic, assign) NSInteger age;
@Property (nonatomic, copy) NSString* desc;
@EnD

@interface PersonInfo : MYJSONModel
@Property (nonatomic, strong) PersonItem* person;
@EnD

NSError* error;
PersonInfo* p = [[PersonInfo alloc] ] initWithDictionary: jsonData error:&error];

NSString* jsonData = @{@"person":{ @"name": @"joke", @"age": @18, @"desc": [NSNull null] }};
server change desc from string to dictionary:
NSString* jsonData = @{@"person":{ @"name": @"joke", @"age": @18, @"desc": @{@"more":@"more detail"} }};

Result: p.person is nil and error is nil.
i want p.person is not nil & p.person.desc could be nil in this case.

when [property.isOptional || !validation] return error should be more careful in traverse properties.

Allowing the wrong type definition does not cause the entire parent node JSONModel to be nil. "// 1) check if property is itself a JSONModel" has the same conditions.
@billinghamj
Copy link
Member

It looks like the changes to the msg declaration don't need to be there - could you undo them if they're not functionally different please?

For the functional change, could you please give me some detail/explanation as to why it's not right now, why it should be changed, what implications that might have, etc.? This seems more like an opinion issue rather than the current behaviour being wrong, but I might not be fully understanding yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants