Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not mapping dictionary #43

Open
MeGaPk opened this issue Mar 4, 2016 · 2 comments
Open

Not mapping dictionary #43

MeGaPk opened this issue Mar 4, 2016 · 2 comments

Comments

@MeGaPk
Copy link

MeGaPk commented Mar 4, 2016

Hello!
Maybe its bug, i wanna report it.

So, we have Class:

@interface TFResponse : NSObject
@property(nonatomic, assign) BOOL status;
@property(nonatomic, weak) NSDictionary *data;
@end

And DICT:

{
    data =     {
        code = 0;
        message = "test message";
    };
    status = 0;
}

After use code:

TFResponse *response = [TFResponse objectFromDictionary:responseObject];
                   NSLog(@"API: TFResponse status: %d", response.status);
                   NSLog(@"API: TFResponse data: %@", response.data);
//                   response.data = responseObject[@"data"];

We have result:

API: TFResponse status: 0
API: TFResponse data: {
}

For fix that, i use:

response.data = responseObject[@"data"];

But maybe it is a bug, and so I decided to report it.

Wait answer.
Best regards,
Ivan.

@aryaxt
Copy link
Owner

aryaxt commented Mar 14, 2016

Hi, unfortunately the library doesn't map dictionaries automatically. However you could write a transformer.

Basically this code intercepts mapping for that key, and calls the block, so you have the opportunity to provide a value to be mapped to the property, and in this case you want to map the exact value without any change, so you simply return currentNode.

[mappingProvider mapFromDictionaryKey:@"data" toPropertyKey:@"data" forClass:[TFResponse class] withTransformer:^id(id currentNode, id parentNode) {
    return currentNode;
}];

Will add this as an enhancement, thanks

@MeGaPk
Copy link
Author

MeGaPk commented Mar 14, 2016

@aryaxt Thanks :) Wait realization 👍

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

No branches or pull requests

2 participants