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

Cannot deserialize change notification - JsonException due to failure converting ChangeType #2801

Open
sebastienlange opened this issue Jan 22, 2025 · 1 comment
Labels
status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:bug A broken experience

Comments

@sebastienlange
Copy link

Describe the bug

This is very similar to #998

Attempting to deserialize the payload of a notification received by a webhook fails with:
The JSON value could not be converted to System.Nullable`1[Microsoft.Graph.Models.ChangeType]. Path: $.value[0].changeType | LineNumber: 5 | BytePositionInLine: 35.

The same problem occurs for Lifecycle notifications:
JSON input formatter threw an exception: The JSON value could not be converted to System.Nullable`1[Microsoft.Graph.Models.LifecycleEventType]. Path: $.value[0].lifecycleEvent | LineNumber: 0 | BytePositionInLine: 472.

Expected behavior

The notifications variable contains a valid ChangeNotificationCollection object with one ChangeNotification.

How to reproduce

The following code will reproduce:

`// This is an actual payload sent by the service that failed in my application
string payload = @"{
""value"": [
{
""subscriptionId"": ""5c748643-b830-4b11-a165-cc4b59c9820c"",
""subscriptionExpirationDateTime"": ""2021-05-15T09:06:46.5737745-07:00"",
""changeType"": ""created"",
""resource"": ""Users/1023ccca-b008-40f6-950a-aa1951a1f0d4/Messages/AAMkADY0ZjM2ZWJlLTEwOGUtNGNiOS04MTFiLWE3Y2UwNjRiZDNiMQBGAAAAAACWRvY6Vjb0SabVPshsbtVRBwAtISQkTseOQLhQ9a0koD2UAAAAAAEMAAAtISQkTseOQLhQ9a0koD2UAAB9Mb9SAAA="",
""resourceData"": {
""@odata.type"": ""#Microsoft.Graph.Message"",
""@odata.id"": ""Users/1023ccca-b008-40f6-950a-aa1951a1f0d4/Messages/AAMkADY0ZjM2ZWJlLTEwOGUtNGNiOS04MTFiLWE3Y2UwNjRiZDNiMQBGAAAAAACWRvY6Vjb0SabVPshsbtVRBwAtISQkTseOQLhQ9a0koD2UAAAAAAEMAAAtISQkTseOQLhQ9a0koD2UAAB9Mb9SAAA="",
""@odata.etag"": ""W/""CQAAABYAAAAtISQkTseOQLhQ9a0koD2UAAB9GwlV"""",
""id"": ""AAMkADY0ZjM2ZWJlLTEwOGUtNGNiOS04MTFiLWE3Y2UwNjRiZDNiMQBGAAAAAACWRvY6Vjb0SabVPshsbtVRBwAtISQkTseOQLhQ9a0koD2UAAAAAAEMAAAtISQkTseOQLhQ9a0koD2UAAB9Mb9SAAA=""
},
""clientState"": ""GraphTutorialState"",
""tenantId"": ""dfa81919-e5d3-4357-82ae-6b1e672fde09""
}
]
}";

var jsonOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
};

// Deserialize the JSON payload into a list of ChangeNotification
// objects
try
{
var notifications = JsonSerializer.Deserialize(payload, jsonOptions);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}`

SDK Version

5.68.0

Latest version known to work for scenario above?

No response

Known Workarounds

Creating my own ChangeNotificationCollection class with own ChangeNotification class where ChangeType and LifecycleEvent are string is working.

Debug output

Click to expand log ```
</details>


### Configuration

- OS: Windows 11
- architecture: x64
- It's not specific to that configuration

### Other information

Of course, the following code also reproduces the problem:

`var changeType = JsonSerializer.Deserialize<Microsoft.Graph.Models.ChangeType>("created");`
@sebastienlange sebastienlange added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Jan 22, 2025
@andrueastman
Copy link
Member

Thanks for raising this @sebastienlange

Any chance you are able to replicate this using the serialization helpers instead? https://learn.microsoft.com/en-us/openapi/kiota/serialization?tabs=csharp#serialization-helpers

@andrueastman andrueastman added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:bug A broken experience
Projects
None yet
Development

No branches or pull requests

2 participants