Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: match android type support for custom attributes #157

Conversation

BrandonStalnaker
Copy link
Contributor

Summary

We discussed this in stand up and determined it makes sense to have iOS match Android behavior in terms of serializing dictionaries when sending to the server but leave the objects as-is when passing to kits.

Testing Plan

Updated unit test to include cases with dictionaries

Master Issue

Closes https://mparticle-eng.atlassian.net/browse/SQDSDKS-4087

@BrandonStalnaker BrandonStalnaker self-assigned this Aug 1, 2022
@"A Date Key":[NSDate date]};
@"A Number Key":@(42),
@"A Date Key":[NSDate date],
@"test Dictionary": @{}};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to use a test dictionary with at least one key/value pair? Or does that not matter for this example?

@@ -47,7 +47,8 @@ - (void)testInstance {
}

NSDictionary *eventInfo = @{@"speed":@25,
@"modality":@"sprinting"};
@"modality":@"sprinting",
@"stats":@{}};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question, especially for unit test, maybe we should have an empty dictionary, then another key with a dictionary with one or two k/v pairs, then finally a key with a dictionary that contains a dictionary in one of its values (nested dictionary) for better coverage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test case for dictionary with values and one with dictionary values in the dictionary

@@ -163,7 +164,8 @@ - (void)testDictionaryRepresentation {
MPEvent *event = [[MPEvent alloc] initWithName:@"Dinosaur Run" type:MPEventTypeOther];
event.duration = eventDuration;
event.customAttributes = @{@"speed":@25,
@"modality":@"sprinting"};
@"modality":@"sprinting",
@"stats":@{}};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment re: other dictionary test cases

UnitTests/MPEventTests.mm Show resolved Hide resolved
@@ -72,8 +72,7 @@ - (id)valueForCaseInsensitiveKey:(NSString *)key {
transformedDictionary[key] = [[NSString alloc] initWithData:obj encoding:NSUTF8StringEncoding];
} else {
MPILogError(@"Data type is not supported as an attribute value: %@ - %@", obj, [[obj class] description]);
NSAssert([obj isKindOfClass:[NSString class]], @"Data type is not supported as an attribute value");
return;
transformedDictionary[key] = [obj description];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember we decided on this (using description) since that's what Android is doing, though this will result in a different string than Android. I think it would be ideal to use a JSON string on both platforms, but I think we decided that was out of scope for this work and could be something we do in the future...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually did this initially but was checking count (example below) which I didn't realize was what was making me not hit that statement. Thanks for making me take another look.

 else if ([obj isKindOfClass:[NSDictionary class]] && [(NSDictionary *)obj count] > 0) {
            transformedDictionary[key] = [obj description];
        } else if ([obj isKindOfClass:[NSMutableDictionary class]] && [(NSDictionary *)obj count] > 0) {
            transformedDictionary[key] = [obj description];
        } else {
            MPILogError(@"Data type is not supported as an attribute value: %@ - %@", obj, [[obj class] description]);
            NSAssert([obj isKindOfClass:[NSString class]], @"Data type is not supported as an attribute value");
            return;
        }
        ```

@BrandonStalnaker BrandonStalnaker dismissed einsteinx2’s stale review August 3, 2022 12:34

changes made Ready for a new look

Copy link
Contributor

@einsteinx2 einsteinx2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@BrandonStalnaker BrandonStalnaker merged commit 001ddad into development Aug 4, 2022
@BrandonStalnaker BrandonStalnaker deleted the feat/4087-Match-Android-Support-For-Custom-Attributes branch August 4, 2022 15:03
mparticle-automation added a commit that referenced this pull request Nov 30, 2022
# [8.9.0](v8.8.1...v8.9.0) (2022-11-30)

### Bug Fixes

* Add class checks to initialize methods ([#165](#165)) ([065df46](065df46))
* Add Hash Methods where isEqual called ([#167](#167)) ([7302e0d](7302e0d))
* Allow null event attributes ([#163](#163)) ([5fd25c6](5fd25c6))
* Move dyld register callback to initialize ([#170](#170)) ([49d3660](49d3660))
* Remove unnecessary calls to removeObserver ([#168](#168)) ([a288ba4](a288ba4))
* Remove Unnecessary Synchronize in Dealloc ([#169](#169)) ([624891b](624891b))

### Features

* match android type support for custom attributes ([#157](#157)) ([c9a34cd](c9a34cd))
* Remove depreciate MPSegment code ([#171](#171)) ([1c04262](1c04262))
* Update Sample App for iOS 16 ([#158](#158)) ([fed8131](fed8131))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants