forked from RestKit/RestKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Using a Custom MIME Type
blakewatters edited this page Nov 16, 2011
·
1 revision
RestKit uses MIME Types to determine how to handle object mapping and serialization operations. If your remote web server is using a MIME Type other than application/xml, application/json, or application/x-www-form-urlencoded you will have to configure RestKit appropriately. There are two parts to the configuration:
- Configuring a parser to handle the MIME Type. This is done via the RKParserRegistry shared instance. In the example below, we'll alias an existing JSON parser to handle a new MIME Type:
[[RKParserRegistry sharedRegistry] setParserClass:[RKJSONParserJSONKit class] forMIMEType:@"application/vnd.company.customobject-v1+json"];
- Configure the object manager to accept and generate content using your custom MIME Type. This is done via simple property accessors on RKObjectManager:
[RKObjectManager sharedManager].serializationMIMEType = @"application/vnd.company.customobject-v1+json";
[RKObjectManager sharedManager].acceptMIMEType = @"application/vnd.company.customobject-v1+json";
The object manager is now configured to accept the custom MIME Type "application/vnd.company.customobject-v1+json" and parse it using the JSONKit parser. When an object is serialized for transport to the remote system via postObject: or putObject:, it will be encoded to JSON and sent with the MIME Type of "application/vnd.company.customobject-v1+json" as well.