How to Deserialize using JsonSerializer A ChangeNotification Collection Properly.?

Richard Simpson 0 Reputation points
2023-06-19T01:01:30.17+00:00
using System.Text.Json;
using Microsoft.Graph.Models;

[HttpPost("lifeCycleNotifications")]
public async Task<ActionResult> HandleAsyncData([FromQuery] string? validationToken = null)
{
// handle validation
if (!string.IsNullOrEmpty(validationToken))
{
// Decode the validation token and return it
string decodedToken = HttpUtility.UrlDecode(validationToken);
return Content(decodedToken, "text/plain");
}

    // handle notifications
    using (StreamReader reader = new StreamReader(Request.Body))
    {
        string content = await reader.ReadToEndAsync().ConfigureAwait(false);

        Console.WriteLine(content);

         var notifications = JsonSerializer.Deserialize<ChangeNotificationCollection>(content);

		//Here notifications is always null. Not having proper deserialization,

        await this.subscriptionService.ResubcribeToNotifications(content);

    }

    return Ok();
}

Microsoft Security | Microsoft Graph
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.