[Fork] https://stackoverflow.com/questions/66495660/net-5-0-signature-change-of-system-text-json-jsonserializer-deserialize

CSharp · Console

/Program.cs

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization.Formatters;
using System.IO;
using System.Data;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Reflection;
using System.Collections.ObjectModel;

using System.Text.Json;
using System.Text.Json.Serialization;

using NUnit.Framework; // Throws NUnit.Framework.AssertionException

//https://stackoverflow.com/questions/66495660/net-5-0-signature-change-of-system-text-json-jsonserializer-deserialize

#nullable enable

	public class MyClass : IJsonOnDeserialized 
	{
		void IJsonOnDeserialized.OnDeserialized() => PostSerialisation();

		internal void PostSerialisation()
		{
			//do stuff
			Console.WriteLine("PostSerialisation() called");
			PostSerialisationCalled = true;
		}
		
		[JsonIgnore]
		public bool PostSerialisationCalled { get; private set; }
	}

    class TestClass
    {
        public static void Test()
        {
			var myClass = JsonSerializer.Deserialize<MyClass>("{}");
			
			Assert.IsTrue(myClass?.PostSerialisationCalled);
		}	
	}

	public class Program
	{
		public static void Main()
		{
			Console.WriteLine("Environment version: {0} ({1}), {2}", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , Environment.Version, Environment.OSVersion);
			Console.WriteLine("System.Text.Json version: " + typeof(JsonSerializer).Assembly.FullName);
			Console.WriteLine();

			try
			{
				TestClass.Test();
			}
			catch (Exception ex)
			{
				Console.WriteLine("Failed with unhandled exception: ");
				Console.WriteLine(ex);
				throw;
			}
		}
	}
;