KeyValueObjectMapping icon indicating copy to clipboard operation
KeyValueObjectMapping copied to clipboard

Nice to have: DCDictionaryMapping

Open albsala opened this issue 11 years ago • 2 comments

It would be nice to have a class like "DCArrayMapping" for NSDictionary, because I have a JSON like this:

{
    "_id":12345,
    "localizedContent":{
        "en":{
            "name":"english name"
        },
        "es":{
            "name":"spanish name"
        }
    }
}

... with an undetermined number of languages, so I'm trying to map it to an object like this:

@interface MyLocalizedContent : NSObject

@property (nonatomic, strong) NSString *name;

@end


@interface MyObject : NSObject

@property (nonatomic, strong) NSNumber *identifier;
@property (nonatomic, strong) NSDictionary *localizedContent;

@end

... and I don't know how to do it without this "DCDictionaryMapping".

albsala avatar Sep 07 '14 16:09 albsala

After hours of tests :) I have solved it using DCCustomParserBlock but it would nice to have a DCDictionaryMapping anyway.

BTW: I have lost so much time figuring out why this didn't work:

DCCustomParser *customParser = [[DCCustomParser alloc] initWithBlockParser:parserBlock
                                                          forAttributeName:@"localizedContent"
                                                        onDestinationClass:[MyObject class]];

until i tried this:

DCCustomParser *customParser = [[DCCustomParser alloc] initWithBlockParser:parserBlock
                                                          forAttributeName:@"_localizedContent"
                                                        onDestinationClass:[MyObject class]];

albsala avatar Sep 08 '14 13:09 albsala

Wow thanks man I lost probably 3 hours trying to figure out why DCCustomParser didn't work. we need docs on DCCustomParser!

d370urn3ur avatar Nov 24 '14 14:11 d370urn3ur