<TRCObjectMapper> Protocol Reference

TRCObjectMapper creates model objects from response data and creates response data from model objects. More...

Inheritance diagram for <TRCObjectMapper>:

Instance Methods

(NSString *) - responseValidationSchemaName
 Specify name of schema file here, to validate response object. More...
 
(id) - objectFromResponseObject:error:
 Creates model object and map values from responseObject into that object. More...
 
(NSString *) - requestValidationSchemaName
 Specify name of schema file here, to validate request object. More...
 
(id) - requestObjectFromObject:error:
 Creates request object, acceptable by request serialization, using object. More...
 

Detailed Description

TRCObjectMapper creates model objects from response data and creates response data from model objects.

It's called mapper because response data already converted using child TRCObjectMappers and TRCValueTransfers, so you'll just map data into your model object here, without any conversion and checking.

Use TRCObjectMapper to reuse mapping code you may have in TRCRequest.responseProcessedFromBody:headers:status:error:, then each your model object will have own TRCObjectMapper.

Each TRCObjectMapper can have schemes just like TRCRequest, to validate and post-process request and response objects.

Method Documentation

◆ responseValidationSchemaName()

- (NSString *) responseValidationSchemaName
optional

Specify name of schema file here, to validate response object.

if this method isn't implemented, ClassName.response.{format} or ClassName.{format} will be used

◆ objectFromResponseObject:error:()

- (id) objectFromResponseObject: (id)  responseObject
error: (NSError **)  error 
optional

Creates model object and map values from responseObject into that object.

If your TRCObjectMapper has scheme for response object, then responseObject already validated and post-processed by child mappers and TRCValueTransformers.

To see more information kind of responseObject, see TRCRequest.responseProcessedFromBody:headers:status:error:

You are free to return nil in that method. That object would be skipped. You also can write into error pointer in case of error. Then request will be finished with that error

Returns
your custom model object or nil
See also
TRCRequest.responseProcessedFromBody:headers:status:error:

◆ requestValidationSchemaName()

- (NSString *) requestValidationSchemaName
optional

Specify name of schema file here, to validate request object.

if this method isn't implemented, ClassName.request.{format} or ClassName.{format} will be used

◆ requestObjectFromObject:error:()

- (id) requestObjectFromObject: (id)  object
error: (NSError **)  error 
optional

Creates request object, acceptable by request serialization, using object.

Returned object would be transformed using child TRCObjectMappers and TRCValueTransformers if specified in schema, and then validated

See TRCRequest.requestBody for details, because same rules applies to returned object.

Returns
request object, which can be used by request serialization. For example JSON request serialization requires NSArray or NSDictionary