mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-24 04:46:01 +08:00
Respect rootKeyPath when returning empty dictionary in response to unmappable representation error
This commit is contained in:
@@ -87,7 +87,7 @@
|
||||
if (operation.error) {
|
||||
if (operation.error.code == RKMappingErrorUnmappableRepresentation) {
|
||||
// If the mapped object is empty, return an empty dictionary and no error
|
||||
return @{};
|
||||
return self.rootKeyPath ? @{ self.rootKeyPath: @{} } : @{};
|
||||
}
|
||||
|
||||
if (error) *error = operation.error;
|
||||
|
||||
@@ -186,8 +186,21 @@
|
||||
NSError *error = nil;
|
||||
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:mapping objectClass:[NSDictionary class] rootKeyPath:nil];
|
||||
NSDictionary *parameters = [RKObjectParameterization parametersWithObject:object requestDescriptor:requestDescriptor error:&error];
|
||||
expect(error).to.beNil();
|
||||
expect(parameters).to.equal(@{});
|
||||
EXP_expect(error).to.beNil();
|
||||
EXP_expect(parameters).to.equal(@{});
|
||||
}
|
||||
|
||||
- (void)testEmptyParameterizationRespectsRootKeyPath
|
||||
{
|
||||
NSDictionary *object = [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", nil];
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[NSDictionary class]];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"key12123" toKeyPath:@"key1-form-name"]];
|
||||
|
||||
NSError *error = nil;
|
||||
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:mapping objectClass:[NSDictionary class] rootKeyPath:@"root"];
|
||||
NSDictionary *parameters = [RKObjectParameterization parametersWithObject:object requestDescriptor:requestDescriptor error:&error];
|
||||
EXP_expect(error).to.beNil();
|
||||
EXP_expect(parameters).to.equal(@{@"root":@{}});
|
||||
}
|
||||
|
||||
- (void)testShouldSerializeNestedObjectsContainingDatesToJSON
|
||||
|
||||
Reference in New Issue
Block a user