mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-24 04:46:01 +08:00
Fix exception that occurs when attempting to build an RKMappingResult after an attempt has been made to map a non-nil, empty response object (such as {})
This commit is contained in:
@@ -77,7 +77,7 @@
|
||||
|
||||
@param object An `NSDictionary` or `NSArray` of `NSDictionary` object representations to be mapped into local domain objects.
|
||||
@param mappingsDictionary An `NSDictionary` wherein the keys are mappable key paths in `object` and the values are `RKMapping` objects specifying how the representations at its key path are to be mapped.
|
||||
@return The receiver, initialized with the given object
|
||||
@return The receiver, initialized with the given object and and dictionary of key paths to mappings.
|
||||
*/
|
||||
- (id)initWithObject:(id)object mappingsDictionary:(NSDictionary *)mappingsDictionary;
|
||||
|
||||
@@ -91,7 +91,7 @@
|
||||
@property (nonatomic, strong, readonly) NSError *error;
|
||||
|
||||
/**
|
||||
The result of the mapping process.
|
||||
The result of the mapping process. A `nil` value indicates that no mappable object representations were found and no mapping was performed.
|
||||
*/
|
||||
@property (nonatomic, strong, readonly) RKMappingResult *mappingResult;
|
||||
|
||||
@@ -166,21 +166,21 @@
|
||||
///-------------------------------
|
||||
|
||||
/**
|
||||
Tells the delegate that the mapper has found a mappable object representation at a key path specified in the `mappingsDictionary` and is about to map it using a mapping.
|
||||
Tells the delegate that the mapper has found one or more mappable object representations at a key path specified in the `mappingsDictionary`.
|
||||
|
||||
@param mapper The mapper operation performing the mapping.
|
||||
@param dictionaryOrArrayOfDictionaries The `NSDictictionary` or `NSArray` of `NSDictionary` object representations that was found at the `keyPath`.
|
||||
@param keyPath The key path that the representation was read from in the `sourceObject`. If the `keyPath` was `[NSNull null]` in the `mappingsDictionary`, it will be given as `nil` to the delegate.
|
||||
*/
|
||||
- (void)mapper:(RKMapperOperation *)mapper didFindRespresentation:(id)dictionaryOrArrayOfDictionaries atKeyPath:(NSString *)keyPath;
|
||||
- (void)mapper:(RKMapperOperation *)mapper didFindRepresentationOrArrayOfRepresentations:(id)dictionaryOrArrayOfDictionaries atKeyPath:(NSString *)keyPath;
|
||||
|
||||
/**
|
||||
Tells the delegate that the mapper failed to find a mappable object at a key path specified in the `mappingsDictionary`.
|
||||
Tells the delegate that the mapper failed to find any mappable object representations at a key path specified in the `mappingsDictionary`.
|
||||
|
||||
@param mapper The mapper operation performing the mapping.
|
||||
@param keyPath The key path that was searched for a mappable object representation.
|
||||
*/
|
||||
- (void)mapper:(RKMapperOperation *)mapper didNotFindReprsentationAtKeyPath:(NSString *)keyPath;
|
||||
- (void)mapper:(RKMapperOperation *)mapper didNotFindRepresentationOrArrayOfRepresentationsAtKeyPath:(NSString *)keyPath;
|
||||
|
||||
///----------------------------------------------
|
||||
/// @name Tracking Child Mapping Operation Status
|
||||
|
||||
@@ -291,8 +291,8 @@ static NSString *RKDelegateKeyPathFromKeyPath(NSString *keyPath)
|
||||
if (mappableValue == nil || mappableValue == [NSNull null] || [self isNullCollection:mappableValue]) {
|
||||
RKLogDebug(@"Found unmappable value at keyPath: %@", keyPath);
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(mapper:didNotFindReprsentationAtKeyPath:)]) {
|
||||
[self.delegate mapper:self didNotFindReprsentationAtKeyPath:RKDelegateKeyPathFromKeyPath(keyPath)];
|
||||
if ([self.delegate respondsToSelector:@selector(mapper:didNotFindRepresentationOrArrayOfRepresentationsAtKeyPath:)]) {
|
||||
[self.delegate mapper:self didNotFindRepresentationOrArrayOfRepresentationsAtKeyPath:keyPath];
|
||||
}
|
||||
|
||||
continue;
|
||||
@@ -301,8 +301,8 @@ static NSString *RKDelegateKeyPathFromKeyPath(NSString *keyPath)
|
||||
// Found something to map
|
||||
foundMappable = YES;
|
||||
RKMapping *mapping = [mappingsByKeyPath objectForKey:keyPath];
|
||||
if ([self.delegate respondsToSelector:@selector(mapper:didFindRespresentation:atKeyPath:)]) {
|
||||
[self.delegate mapper:self didFindRespresentation:mappableValue atKeyPath:RKDelegateKeyPathFromKeyPath(keyPath)];
|
||||
if ([self.delegate respondsToSelector:@selector(mapper:didFindRepresentationOrArrayOfRepresentations:atKeyPath:)]) {
|
||||
[self.delegate mapper:self didFindRepresentationOrArrayOfRepresentations:mappableValue atKeyPath:keyPath];
|
||||
}
|
||||
|
||||
mappingResult = [self performMappingForObject:mappableValue atKeyPath:keyPath usingMapping:mapping];
|
||||
@@ -353,7 +353,7 @@ static NSString *RKDelegateKeyPathFromKeyPath(NSString *keyPath)
|
||||
|
||||
RKLogDebug(@"Finished performing object mapping. Results: %@", results);
|
||||
|
||||
self.mappingResult = [[RKMappingResult alloc] initWithDictionary:results];
|
||||
if (results) self.mappingResult = [[RKMappingResult alloc] initWithDictionary:results];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
{
|
||||
// Flatten results down into a single array
|
||||
NSMutableArray *collection = [NSMutableArray array];
|
||||
for (id object in [_keyPathToMappedObjects allValues]) {
|
||||
for (id object in [self.keyPathToMappedObjects allValues]) {
|
||||
// We don't want to strip the keys off of a mapped dictionary result
|
||||
if (NO == [object isKindOfClass:[NSDictionary class]] && [object respondsToSelector:@selector(allObjects)]) {
|
||||
[collection addObjectsFromArray:[object allObjects]];
|
||||
|
||||
@@ -650,7 +650,7 @@
|
||||
|
||||
id userInfo = [RKTestFixture parsedObjectWithContentsOfFixture:@"user.json"];
|
||||
RKMapperOperation *mapper = [[RKMapperOperation alloc] initWithObject:userInfo mappingsDictionary:mappingsDictionary];
|
||||
[[mockDelegate expect] mapper:mapper didFindRespresentation:OCMOCK_ANY atKeyPath:nil];
|
||||
[[mockDelegate expect] mapper:mapper didFindRepresentationOrArrayOfRepresentations:OCMOCK_ANY atKeyPath:nil];
|
||||
mapper.delegate = mockDelegate;
|
||||
[mapper start];
|
||||
[mockDelegate verify];
|
||||
@@ -665,7 +665,7 @@
|
||||
id userInfo = [RKTestFixture parsedObjectWithContentsOfFixture:@"user.json"];
|
||||
RKMapperOperation *mapper = [[RKMapperOperation alloc] initWithObject:userInfo mappingsDictionary:mappingsDictionary];
|
||||
id mockDelegate = [OCMockObject niceMockForProtocol:@protocol(RKMapperOperationDelegate)];
|
||||
[[mockDelegate expect] mapper:mapper didNotFindReprsentationAtKeyPath:@"users"];
|
||||
[[mockDelegate expect] mapper:mapper didNotFindRepresentationOrArrayOfRepresentationsAtKeyPath:@"users"];
|
||||
mapper.delegate = mockDelegate;
|
||||
[mapper start];
|
||||
[mockDelegate verify];
|
||||
|
||||
Reference in New Issue
Block a user