using System.Collections;
using System.Collections.Generic;
using System.Text.Json.Serialization;
public string BaseProperty { get; set; }
public class Derived : Base
public string DerivedProperty { get; set; }
public static void Test()
Console.WriteLine("Serializing with typeof(Base):");
var value = new Derived { BaseProperty = "hello", DerivedProperty = "there" };
var json = JsonSerializer.Serialize(value, typeof(Base));
Console.WriteLine("\nSerializing with typeof(Derived):");
Console.WriteLine(JsonSerializer.Serialize(value, typeof(Derived)));
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("Failed with unhandled exception: ");