Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

'Invalid type in JSON write (MSGraphEmailAddress)' #27

Open
SteveDCronin opened this issue Sep 10, 2019 · 2 comments · May be fixed by #36
Open

'Invalid type in JSON write (MSGraphEmailAddress)' #27

SteveDCronin opened this issue Sep 10, 2019 · 2 comments · May be fixed by #36
Labels

Comments

@SteveDCronin
Copy link

SteveDCronin commented Sep 10, 2019

In trying to create a new contact I am continuing to use the Objective-C code snippet here:
https://docs.microsoft.com/en-us/graph/api/user-post-contacts?view=graph-rest-1.0&tabs=objc

It occurs here:
contact = [[MSGraphContact alloc] init];
...
NSError *error=nil;
NSData *contactData = [contact getSerializedDataWithError:&error];

There error is:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (MSGraphEmailAddress)'

The contact has a single email address constructed like this:
NSMutableArray *emailAddressesList = [[NSMutableArray alloc] init];
MSGraphEmailAddress *emailAddress = [[MSGraphEmailAddress alloc] init];
[emailAddress setAddress:@"[email protected]"];
[emailAddress setName:@"Tim Cook"];
[emailAddressesList addObject: emailAddress];
[contact setEmailAddresses:emailAddressesList];

Please clarify 2 things:

  1. why the method terminates rather than report the error?
  2. what am I doing wrong in constructing the MSGraphEmailAddress

Thanks you any help.

BTW: further testing shows that I get the same type error if I construct an address:
'NSInvalidArgumentException', reason: 'Invalid type in JSON write (MSGraphPhysicalAddress)'
AB#7053

@ghost ghost added the ToTriage label Sep 10, 2019
@darrelmiller
Copy link

Hey @jasonjoh , might you have any idea why this is failing?

@tobihagemann
Copy link

I'm getting a similar error when creating a folder.

MSGraphDriveItem *newFolder = [[MSGraphDriveItem alloc] init];
newFolder.name = @"foo";
newFolder.folder = [[MSGraphFolder alloc] init];
NSError *error;
NSData *newFolderData = [newFolder getSerializedDataWithError:&error];

This leads to the error:

Invalid type in JSON write (MSGraphFolder)

I think the issue is that -[getSerializedDataWithError:] in MSObject serializes the dictionary shallowly. In my case, it tries to create a JSON out of a dictionary that contains an MSGraphFolder value, which it cannot do. Before that's possible, it has to serialize that object into a dictionary. Basically, MSObject has to serialize the dictionary deeply. Or make sure that the dictionary never contains invalid objects in the first place, see NSJSONSerialization documentation.

tobihagemann added a commit to tobihagemann/msgraph-sdk-objc-models that referenced this issue Oct 8, 2019
@ddyett ddyett added the promote label Jan 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
5 participants