This can be done using mtl_JSONDictionaryTransformerWithModelClass: tranformer introduced by Mantle some time ago.
Take a look at an example taken from the mantle project file itself :
@interface GHIssue : MTLModel <MTLJSONSerializing> @property (nonatomic, strong, readonly) GHUser *assignee; @end
@implementation GHIssue + (NSDictionary *)JSONKeyPathsByPropertyKey { return @{ @"assignee": @"assignee", }; } + (NSValueTransformer *)assigneeJSONTransformer { return [NSValueTransformer mtl_JSONDictionaryTransformerWithModelClass:[GHUser class]]; } @end
Assuming GHUser is a subclass of MTLModel that conforms to the MTLJSONSerializing protocol, everything should work fine.
UPDATE: The above solution is now deprecated. The correct way to use it will now be
return [MTLJSONAdapter dictionaryTransformerWithModelClass:GHUser.class];
inside the assigneeJSONTransformer method.
source share