Skip to content

Commit

Permalink
Stabilize the keys for descriptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasvl committed Nov 8, 2018
1 parent 3bb8e4e commit aa4db3c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Source/Objects/GTLRObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Source/Tests/GTLRObjectTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -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\"}");

Expand Down

0 comments on commit aa4db3c

Please sign in to comment.