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 create ChangeNotificationCollection from JSON #2138

Closed
jasonjoh opened this issue Sep 20, 2023 · 0 comments · Fixed by #2150
Closed

Cannot create ChangeNotificationCollection from JSON #2138

jasonjoh opened this issue Sep 20, 2023 · 0 comments · Fixed by #2150
Assignees
Labels

Comments

@jasonjoh
Copy link
Member

Creating a ChangeNotificationCollection from a JSON stream using CreateFromDiscriminatorValue results in an object with all fields set to null. This seems to be caused by the BackingStore never getting initialized, since there is no constructor for this class.

Note this issue also exists in the Beta SDK, see microsoftgraph/msgraph-beta-sdk-dotnet#730

Repro code

using Microsoft.Graph.Models;
using Microsoft.Kiota.Serialization.Json;

var json = @"{
    ""value"": [
        {
            ""changeType"": ""updated"",
            ""subscriptionId"": ""c224ac82-d3f3-4079-80ed-b6cd355e0f56"",
            ""resource"": ""external"",
            ""clientState"": null,
            ""resourceData"": {
                ""@odata.type"": ""#Microsoft.Graph.connector"",
                ""@odata.id"": ""external"",
                ""id"": ""cf6c33ae-e462-41c8-928b-88a8dd410f23"",
                ""state"": ""enabled"",
                ""connectorsTicket"": ""eyJhbGciOiJIU...""
            },
            ""subscriptionExpirationDateTime"": ""2023-09-20T20:39:46.8577199+00:00"",
            ""tenantId"": ""cf6c33ae-e462-41c8-928b-88a8dd410f23""
        }
    ],
    ""validationTokens"": [
        ""eyJ0eXAiOiJKV1...""
    ]
}";

using var memStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(json));

var parseNode = new JsonParseNodeFactory().GetRootParseNode("application/json", memStream);
var changeNotifications = parseNode.GetObjectValue(ChangeNotificationCollection.CreateFromDiscriminatorValue);

Console.WriteLine($"changeNotifications.Value: {(changeNotifications?.Value == null ? "NULL" : changeNotifications.Value.Count)}");
Console.WriteLine($"changeNotifications.ValidationTokens: {(changeNotifications?.ValidationTokens == null ? "NULL" : changeNotifications.ValidationTokens.Count)}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants