Created
February 14, 2012 19:22
-
-
Save bmorton/1829425 to your computer and use it in GitHub Desktop.
RestKit Serializations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ECOrder.m | |
static RKObjectMapping *objectMapping = nil; | |
static RKObjectMapping *serializationMapping = nil; | |
+ (RKObjectMapping*)objectMapping { | |
if (objectMapping == nil) { | |
objectMapping = [RKObjectMapping mappingForClass:self]; | |
[objectMapping mapKeyPath:@"id" toAttribute:@"orderID"]; | |
[objectMapping mapKeyPath:@"user_id" toAttribute:@"userID"]; | |
[objectMapping mapKeyPath:@"payment_profile_id" toAttribute:@"paymentProfileID"]; | |
[objectMapping mapKeyPath:@"state" toAttribute:@"state"]; | |
[objectMapping mapKeyPath:@"items" toRelationship:@"items" withMapping:[ECOrderItem objectMapping]]; | |
} | |
return objectMapping; | |
} | |
+ (RKObjectMapping*)serializationMapping { | |
if (serializationMapping == nil) { | |
serializationMapping = [RKObjectMapping serializationMapping]; | |
serializationMapping.rootKeyPath = @"order"; | |
[serializationMapping mapKeyPath:@"orderID" toAttribute:@"id"]; | |
[serializationMapping mapKeyPath:@"userID" toAttribute:@"user_id"]; | |
[serializationMapping mapKeyPath:@"paymentProfileID" toAttribute:@"payment_profile_id"]; | |
[serializationMapping mapKeyPath:@"items" toRelationship:@"items" withMapping:[ECOrderItem serializationMapping] serialize:YES]; | |
} | |
return serializationMapping; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static RKObjectMapping *objectMapping = nil; | |
static RKObjectMapping *serializationMapping = nil; | |
+ (RKObjectMapping*)objectMapping { | |
if (objectMapping == nil) { | |
objectMapping = [RKObjectMapping mappingForClass:self]; | |
[objectMapping mapKeyPath:@"id" toAttribute:@"orderItemID"]; | |
[objectMapping mapKeyPath:@"order_id" toAttribute:@"orderID"]; | |
[objectMapping mapKeyPath:@"inventory_id" toAttribute:@"inventoryID"]; | |
[objectMapping mapKeyPath:@"unit_price" toAttribute:@"unitPrice"]; | |
[objectMapping mapKeyPath:@"quantity" toAttribute:@"quantity"]; | |
} | |
return objectMapping; | |
} | |
+ (RKObjectMapping*)serializationMapping { | |
if (serializationMapping == nil) { | |
serializationMapping = [RKObjectMapping serializationMapping]; | |
serializationMapping.rootKeyPath = @"order_item"; | |
[serializationMapping mapKeyPath:@"inventoryID" toAttribute:@"inventory_id"]; | |
[serializationMapping mapKeyPath:@"quantity" toAttribute:@"quantity"]; | |
} | |
return serializationMapping; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[manager.mappingProvider setMapping:[ECOrder objectMapping] forKeyPath:@"order"]; | |
[manager.mappingProvider setSerializationMapping:[ECOrder serializationMapping]forClass:[ECOrder class]]; | |
[manager.mappingProvider setMapping:[ECOrderItem objectMapping] forKeyPath:@"order_items"]; | |
[manager.mappingProvider setSerializationMapping:[ECOrderItem serializationMapping] forClass:[ECOrderItem class]]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment