BWObjectSerializer 0.0.1

BWObjectSerializer 0.0.1

TestsTested
LangLanguage Obj-CObjective C
License Apache 2
ReleasedLast Release Dec 2014

Maintained by Unclaimed.


Downloads

Total100
Week0
Month0

Installs

Apps6
Test Targets1
powered by Segment

GitHub

Stars11
Watchers3
Forks0
Issues0
Contributors3
Pull Requests0

Code

Files7
LOCLines of Code 168


  • By
  • Bruno Wernimont

Small library that transform an object into a dictionary that can be send to a web service.

Work well with string, number and date others data must be converted. By default date are parsed with the rails date time format.

An object

Item *item = [[Item alloc] init];
item.title = @"Title";
item.itemID = [NSNumber numberWithInt:15];
item.createdAt = [NSDate date];

Serializing mapping

[BWObjectSerializerMapping mappingForObject:[Item class] block:^(BWObjectSerializerMapping *serializer) {
    [serializer mapKeyPath:@"title" toAttribute:@"title"];
    [serializer mapKeyPath:@"itemID" toAttribute:@"id"];

    [serializer mapKeyPath:@"imagePath" toAttribute:@"image_url" valueBlock:^id(id value, id object) {
        return @"custom value";
    }];

    [serializer mapKeyPath:@"createdAt" toAttribute:@"created_at" withDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];

    [[BWObjectSerializer shared] registerSerializer:serializer withRootKeyPath:@"item"];
}];

Serialize the object

NSDictionary *dict = [[BWObjectSerializer shared] serializeObject:item];

Or

NSDictionary *dict [[BWObjectSerializer shared] serializeObject:item withMapping:mapping];

Will generate this dictionary:

{
        item =     {
            "created_at" = "2012-07-20T21:56:26Z";
            "image_url" = "custom value";
            title = Title;
        };
}

ARC

BWStatusBarOverlay is ARC only.

Contact

Bruno Wernimont