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.Runtime.Serialization;
using Utf8Json.Resolvers;
public string Lecturer { get; set; }
public WeekDays WeekDay { get; set; }
public enum WeekDays : byte
public static class Utf8JsonConfiguration
static public IJsonFormatterResolver Resolver { get; } =
CompositeResolver.Create(EnumResolver.UnderlyingValue, StandardResolver.Default);
public static void Test()
var physics_1 = new Physics { Lecturer = "Andrew", WeekDay = WeekDays.Monday };
var v1 = JsonSerializer.Serialize(physics_1, Utf8JsonConfiguration.Resolver);
Console.WriteLine(Encoding.UTF8.GetString(v1));
var physics_2 = JsonSerializer.Deserialize<Physics>(v1, Utf8JsonConfiguration.Resolver);
Assert.AreEqual(physics_1.Lecturer, physics_2.Lecturer);
Assert.AreEqual(physics_1.WeekDay, physics_2.WeekDay);
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];