microsoft-graph-apimicrosoft-graph-sdks

How do I use CreateFromDiscriminatorValue?


I have a webhook getting notifications from Teams, and want to deserialize the returned data.

I think the type I'm after is ChangeNotificationCollectionResponse but couldn't find this explicitly in the docs anywhere?

Anyhow, if that is the correct type, how are we meant to deserialize it? I see that ChangeNotificationCollectionResponse has a method CreateFromDiscriminatorValue, and again can't find any docs on that aside from the boilerplate "this thing exists" docs. Do we use that somehow, and if so can you provide an example or can we just use a regular json deserializer?

Thanks!


Solution

  • I think one way is to create an instance of JsonParseNode and call the GetObjectValue method.

    var jsonContent = "{\"value\":[{\"subscriptionId\":\"xxx\",\"subscriptionExpirationDateTime\":\"xxx\",\"changeType\":\"created\",...]}";
    var jsonParseNode = new JsonParseNode(JsonDocument.Parse(jsonContent).RootElement);
    var collectionResponse = jsonParseNode.GetObjectValue(ChangeNotificationCollectionResponse.CreateFromDiscriminatorValue);