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

While I call indentify with a my traits contains a NSDate object , it will crash because 'Invalid type in JSON write (__NSTaggedDate)' #959

Closed
sanhue0302 opened this issue Nov 3, 2020 · 5 comments

Comments

@sanhue0302
Copy link

sanhue0302 commented Nov 3, 2020

as title, I got this problem on 4.1

after look into the source code
I notice that function SEGCoerceDictionary in SEGAnalyticsUtils on 3.9, it was

NSDictionary *SEGCoerceDictionary(NSDictionary *dict)
{
    // make sure that a new dictionary exists even if the input is null
    dict = dict ?: @{};
    // assert that the proper types are in the dictionary
    dict = [dict serializableDeepCopy];
    // coerce urls, and dates to the proper format
    return SEGCoerceJSONObject(dict);
}

but on 4.1.1, it became

NSDictionary *SEGCoerceDictionary(NSDictionary *dict)
{
    // make sure that a new dictionary exists even if the input is null
    dict = dict ?: @{};
    // assert that the proper types are in the dictionary
    dict = [dict serializableDeepCopy];
    return dict;
}

I found that the conversion code was moving into serializableDeepCopy
and the implementation is in - (id)serializableDeepCopy:(BOOL)mutable

       ...

        if ([aValue conformsToProtocol:@protocol(SEGSerializableDeepCopy)]) {
            theCopy = [aValue serializableDeepCopy:mutable];
        } else if ([aValue conformsToProtocol:@protocol(NSCopying)]) {
            theCopy = [aValue copy];
        } else if ([aValue conformsToProtocol:@protocol(SEGSerializable)]) {
            theCopy = [aValue serializeToAppropriateType];
        } else {
            theCopy = aValue;
        }
        

In my case, when aValue is kind of class NSDate, it run into conforms to protocol NSCoping.
I think it should run into conforms to SEGSerializable first to convert NSDate to NSString

For now, I will convert NSDate to NSString myself.

Why does it dismiss on 4.1?

@sanhue0302 sanhue0302 changed the title While traits contains a NSDate object, it cause crash because "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (__NSTaggedDate)'" While I call indentify with a my traits contains a NSDate object , it will crash because 'Invalid type in JSON write (__NSTaggedDate)' Nov 3, 2020
@bsneed
Copy link
Contributor

bsneed commented Nov 3, 2020

Thanks @sanhue0302 ! I'll get this fixed ASAP.

@bsneed
Copy link
Contributor

bsneed commented Nov 4, 2020

Fixed! Will be on master to try out shortly. Release coming soon.

@bsneed bsneed closed this as completed Nov 4, 2020
@allreddy
Copy link

allreddy commented Nov 9, 2020

Hello there, we just upgraded to 4.1.1 via Carthage and running into this crash.

Any timeline for when this fix will be released, ie. 4.1.2?

@iosjillian
Copy link

We're also experiencing this issue and wondering about a timeline since we're preparing an app store release. Thanks for tracking this down and fixing it so quickly!

@bsneed
Copy link
Contributor

bsneed commented Nov 12, 2020

@iosjillian @allreddy we're going to do a 4.1.2 release today.

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

No branches or pull requests

4 participants