diff --git a/Source/Objects/GTLRObject.m b/Source/Objects/GTLRObject.m index a976b413d..66812d82f 100644 --- a/Source/Objects/GTLRObject.m +++ b/Source/Objects/GTLRObject.m @@ -445,7 +445,7 @@ - (NSString *)JSONDescription { NSMutableString *descStr = [NSMutableString stringWithString:@"{"]; NSString *spacer = @""; - for (NSString *key in _json) { + for (NSString *key in [[_json allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]) { NSString *value = nil; // show question mark for JSON keys not supported by a declared property: // foo?:"Hi mom." @@ -456,7 +456,8 @@ - (NSString *)JSONDescription { if ([rawValue isKindOfClass:[NSDictionary class]]) { // for dictionaries, show the list of keys: // {key1,key2,key3} - NSString *subkeyList = [((NSDictionary *)rawValue).allKeys componentsJoinedByString:@","]; + NSArray *subKeys = [((NSDictionary *)rawValue).allKeys sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; + NSString *subkeyList = [subKeys componentsJoinedByString:@","]; value = [NSString stringWithFormat:@"{%@}", subkeyList]; } else if ([rawValue isKindOfClass:[NSArray class]]) { // for arrays, show the number of items in the array: diff --git a/Source/Tests/GTLRObjectTest.m b/Source/Tests/GTLRObjectTest.m index 084eb716d..88b831448 100644 --- a/Source/Tests/GTLRObjectTest.m +++ b/Source/Tests/GTLRObjectTest.m @@ -1718,7 +1718,7 @@ - (void)testObjectDescription { obj.child = obj2; XCTAssertEqualObjects([obj JSONDescription], - @"{a.num:123 a_bool:1 a_str:\"a string\" arrayNumber:[3] unknown?:\"something\" child:{a_str,un}}"); + @"{a.num:123 a_bool:1 a_str:\"a string\" arrayNumber:[3] child:{a_str,un} unknown?:\"something\"}"); XCTAssertEqualObjects([obj2 JSONDescription], @"{a_str:\"kid\" un?:\"value\"}");