How do I change values of attributes when mapping to REST using Restkit? How do I change values of attributes when mapping to REST using Restkit? json json

How do I change values of attributes when mapping to REST using Restkit?


You can solve this by creating a category for the (NSManagedObject) class you're mapping, and adding special properties in this category that will be used by Restkit.So add a property typeString in the category that converts the enum (type) to a string and map the attribute "typeString" to json, instead of "type". It looks like this for receiving:

[mapping mapKeyPath:@"type" toAttribute:@"typeString"]

and like this for sending:

[serializationMapping mapKeyPath:@"typeString" toAttribute:@"type"]

This way you don't need to use objectLoader:willMapData: at all, and the conversion is nicely embedded in the object (category).