using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Collections.ObjectModel;
using System.Text.Json.Serialization;
public string? id { get; set; }
public string? Name { get; set; }
public string Address { get; set; }
[JsonConverter(typeof(JsonStringEnumConverter))]
public CustomerType Type {get; set;}
[JsonConverter(typeof(JsonStringEnumConverter))]
public static void Test()
var customer = new Customer
Type = Customer.CustomerType.EXISTING,
var json = JsonSerializer.Serialize(customer, new JsonSerializerOptions { WriteIndented = true });
var customer2 = JsonSerializer.Deserialize<Customer>(json);
Assert.AreEqual(customer?.Type, customer2?.Type);
var json2 = JsonSerializer.Serialize(customer2, new JsonSerializerOptions { WriteIndented = true });
Console.WriteLine("Round-tripped {0}:", customer2);
Console.WriteLine(json2);
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: ");