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:

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

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

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.

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.

Declared In

RKMIMETypeSerialization.h

objectFromData:MIMEType:error:

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

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

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.

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.

Declared In

RKMIMETypeSerialization.h

registerClass:forMIMEType:

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

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

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.

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.

Declared In

RKMIMETypeSerialization.h

registeredMIMETypes

+ (NSSet *)registeredMIMETypes
Discussion

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

Return Value

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

Declared In

RKMIMETypeSerialization.h

serializationClassForMIMEType:

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

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

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.

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.

Declared In

RKMIMETypeSerialization.h

unregisterClass:

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

Unregisters the given serialization class from handling any MIME Types.

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

Parameters

serializationClass

The class conforming to the RKSerialization protocol to be unregistered.

Declared In

RKMIMETypeSerialization.h