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

Event JSON payload cannot be deserialized by Microsoft Graph #1890

Closed
dkonyayev opened this issue May 10, 2023 · 4 comments
Closed

Event JSON payload cannot be deserialized by Microsoft Graph #1890

dkonyayev opened this issue May 10, 2023 · 4 comments

Comments

@dkonyayev
Copy link

Describe the bug
We have been using Microsoft.Graph nuget package version 4.X to create a JSON event payload to use with REST POST API call to Microsoft Graph. After we upgraded to version 5.X, the payload is no longer accepted by the graph service.

Specifically, some of the JSON attributes were removed from the models. In the example below, the version 5

"OdataType": "#microsoft.graph.attendee"

used to be

"@odata.type": "microsoft.graph.attendee"

{
"Attendees": [
{
"Type": 0,
"AdditionalData": {},
"BackingStore": {
"InitializationCompleted": true,
"ReturnOnlyChangedValues": false
},
"EmailAddress": {
"AdditionalData": {},
"Address": "dkonyayev@metlife-qa.com",
"BackingStore": {
"InitializationCompleted": true,
"ReturnOnlyChangedValues": false
}
},
"OdataType": "#microsoft.graph.attendee"
}
],
"Body": {
"AdditionalData": {},
"BackingStore": {
"InitializationCompleted": true,
"ReturnOnlyChangedValues": false
},
"Content": "Paid Time Off - 12345",
"ContentType": 0
},
"BodyPreview": "Microsoft.Graph.Models.ItemBody",
"End": {
"AdditionalData": {},
"BackingStore": {
"InitializationCompleted": true,
"ReturnOnlyChangedValues": false
},
"DateTime": "5/11/2023 12:00:00 AM",
"TimeZone": "Eastern Standard Time"
},
"IsAllDay": true,
"IsReminderOn": false,
"Locations": [
{
"AdditionalData": {},
"BackingStore": {
"InitializationCompleted": true,
"ReturnOnlyChangedValues": false
},
"DisplayName": "12345"
}
],
"ResponseRequested": false,
"ShowAs": 4,
"Start": {
"AdditionalData": {},
"BackingStore": {
"InitializationCompleted": true,
"ReturnOnlyChangedValues": false
},
"DateTime": "5/10/2023 12:00:00 AM",
"TimeZone": "Eastern Standard Time"
},
"Subject": "Konyayev, Dmitriy: Paid Time Off",
"AdditionalData": {},
"BackingStore": {
"InitializationCompleted": true,
"ReturnOnlyChangedValues": false
},
"OdataType": "#microsoft.graph.event"
}

To Reproduce
Create JSON payload from Event and POST to Microsoft Graph to create calendar event.

Expected behavior
We expect the Event payload generated by version 5+ of nuget package to be consumable by Microsoft Graph service.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

@ghost ghost added the Needs: Triage label May 10, 2023
@andrueastman
Copy link
Member

Thanks for raising this @dkonyayev,

Any chance you can share the method used to serialize the models in this case? The graph client library should handle serialization /deserialization and successful requests made as documented at the link below.

https://learn.microsoft.com/en-us/graph/api/calendar-post-events?view=graph-rest-1.0&tabs=csharp#request

@dkonyayev
Copy link
Author

dkonyayev commented May 23, 2023

@andrueastman So a very simple example is serialization of "odatatype" property. It used to seralize as property name "@odata.type" in v4, and in v5 it seralizes as "odatatype".

Microsoft Graph does not recognize "odatatype" property, and it expects "@odata.type". I tested it by manually renaming properties to get the payload to process.

Our code looks like this

var opts = new System.Text.Json.JsonSerializerOptions
            {
                PropertyNameCaseInsensitive = true,
                DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull,
                Converters =
                {
                    new JsonStringEnumConverter()
                }
            };

System.Text.Json.JsonSerializer.Serialize(createEvent, opts)

@WadeTheFade
Copy link

This looks related to #1933 and #1729

@andrueastman
Copy link
Member

We'll close this for now.

With the latest version of the Microsoft.Graph.Core, you should also be able to use the serialization helper methods available from Kiota abstractions. https://www.nuget.org/packages/Microsoft.Graph.Core/3.1.1

var serializedString = KiotaJsonSerializer.SerializeAsString(date);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants