using System.Collections;
using System.Collections.Generic;
using System.Text.Json.Serialization;
public string ProductId { get; set; }
[System.Text.Json.Serialization.JsonExtensionData]
public Dictionary<string, object> Properties { get; set; } = new ();
public Product(string productId) : base()
public class Product : Dictionary<string, object>
public string ProductId { get; set; }
public Product(string productId) : base()
public static void Test()
var p = new Product("ABC123");
p.Properties["foo"] = "bar";
var json = JsonSerializer.Serialize(p);
Assert.AreEqual(@"{""ProductId"":""ABC123"",""foo"":""bar""}", json);
var p2 = JsonSerializer.Deserialize<Product>(json);
Assert.AreEqual(p.ProductId, p2.ProductId);
var json2 = JsonSerializer.Serialize(p2);
Assert.AreEqual(json, json2);
var converter = new JsonSerializerOptions().GetConverter(typeof(Original.Product));
Console.WriteLine("Converter used for {0}: {1}", typeof(Original.Product), converter);
public static void Main()
Console.WriteLine("Environment version: {0} ({1})", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , GetNetCoreVersion());
Console.WriteLine("System.Text.Json version: " + typeof(JsonSerializer).Assembly.FullName);
Console.WriteLine("Failed with unhandled exception: ");
public static string GetNetCoreVersion()
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
var assemblyPath = assembly.Location.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
return assemblyPath[netCoreAppIndex + 1];