Inherits from NSObject
Declared in RKMIMETypeSerialization.h

Overview

The RKMIMETypeSerialization class provides support for the registration of classes conforming to the RKSerialization protocol by MIME Type and the serialization and deserialization of content by MIME Type. Serialization implementations may be registered by an exact string match (i.e. ‘application/json’ for a JSON serialization implementation) or by regular expression to match MIME Type by pattern.

Tasks

Managing MIME Type Registrations

Serializing and Deserializing Content by MIME Type

  • + objectFromData:MIMEType:error:

    Deserializes and returns a Foundation object representation of the given UTF-8 encoded data in the serialization format for the given MIME Type.

  • + dataFromObject:MIMEType:error:

    Serializes and returns a UTF-8 encoded data representation of the given Foundation object in the serialization format for the given MIME Type.

Class Methods

dataFromObject:MIMEType:error:

Serializes and returns a UTF-8 encoded data representation of the given Foundation object in the serialization format for the given MIME Type.

+ (NSData *)dataFromObject:(id)object MIMEType:(NSString *)MIMEType error:(NSError **)error

Parameters

object

The Foundation object to serialized.

MIMEType

The MIME Type of the serialization format the data is in.

error

A pointer to an NSError object.

Return Value

A Foundation object from the serialized data in data, or nil if an error occurs.

Discussion

On invocation, searches the registrations by invoking serializationClassForMIMEType: with the given MIME Type and then invokes objectFromData:error: on the RKSerialization conformant class returned. If no serialization implementation is found to handle the given MIME Type, nil is returned and the given error pointer will be set to an NSError object with the RKMissingSerializationForMIMETypeError code.

Declared In

RKMIMETypeSerialization.h

objectFromData:MIMEType:error:

Deserializes and returns a Foundation object representation of the given UTF-8 encoded data in the serialization format for the given MIME Type.

+ (id)objectFromData:(NSData *)data MIMEType:(NSString *)MIMEType error:(NSError **)error

Parameters

data

The UTF-8 encoded data representation of the object to be deserialized.

MIMEType

The MIME Type of the serialization format the data is in.

error

A pointer to an NSError object.

Return Value

A Foundation object from the serialized data in data, or nil if an error occurs.

Discussion

On invocation, searches the registrations by invoking serializationClassForMIMEType: with the given MIME Type and then invokes objectFromData:error: on the RKSerialization conformant class returned. If no serialization implementation is found to handle the given MIME Type, nil is returned and the given error pointer will be set to an NSError object with the RKMissingSerializationForMIMETypeError code.

Declared In

RKMIMETypeSerialization.h

registerClass:forMIMEType:

Registers the given serialization class to handle content for the given MIME Type identifier.

+ (void)registerClass:(Class<RKSerialization>)serializationClass forMIMEType:(id)MIMETypeStringOrRegularExpression

Parameters

serializationClass

The class conforming to the RKSerialization protocol to be registered as handling the given MIME Type.

MIMETypeStringOrRegularExpression

A string or regular expression specifying the MIME Type(s) that given serialization implementation is to be registered as handling.

Discussion

MIME Types may be given as either a string or as a regular expression that matches the MIME Types for which the given serialization should handle. Serializations are searched in the reverse order of their registration. If a registration is made for an already registered MIME Type, the new registration will take precedence.

Declared In

RKMIMETypeSerialization.h

registeredMIMETypes

Returns a set containing the string values for all MIME Types for which a serialization implementation has been registered.

+ (NSSet *)registeredMIMETypes

Return Value

An NSSet object whose elements are NSString values enumerating the registered MIME Types.

Declared In

RKMIMETypeSerialization.h

serializationClassForMIMEType:

Returns the serialization class registered to handle the given MIME Type.

+ (Class<RKSerialization>)serializationClassForMIMEType:(NSString *)MIMEType

Parameters

MIMEType

The MIME Type for which to return the registered RKSerialization conformant class.

Return Value

A class conforming to the RKSerialization protocol registered for the given MIME Type or nil if none was found.

Discussion

Searches the registrations in reverse order for the first serialization implementation registered to handle the given MIME Type. Matches are determined by doing a lowercase string comparison if the MIME Type was registered with a string identifier or by evaluating a regular expression match against the given MIME Type if registered with a regular expression.

Declared In

RKMIMETypeSerialization.h

unregisterClass:

Unregisters the given serialization class from handling any MIME Types.

+ (void)unregisterClass:(Class<RKSerialization>)serializationClass

Parameters

serializationClass

The class conforming to the RKSerialization protocol to be unregistered.

Discussion

After this method is invoked, invocations of serializationForMIMEType: will no longer return the unregistered serialization class.

Declared In

RKMIMETypeSerialization.h