using System.Text.Json.Serialization;
using System.Collections.Generic;
public static void Main()
IEnumerable<LaborDetailPostingRecord> y = new List<LaborDetailPostingRecord> { new LaborDetailPostingRecord("123") };
Console.WriteLine(JsonSerializer.Serialize(y));
Console.WriteLine(DateTime.Now.ToUniversalTime().ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff"));
var i = new CreateLaborCodeRequestModel(new LaborCodeModel { Code = "ABC" }) { Name = "Ryan" };
Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(i.NewLaborCode));
public class LaborDetailPostingRecord
public string PKey { get; }
public LaborDetailPostingRecord(string pkey)
public class CustomJsonConverterDynamic : JsonConverter<LaborCodeModel>
public override LaborCodeModel Read(ref Utf8JsonReader reader, Type type, JsonSerializerOptions options)
throw new NotImplementedException();
public override void Write(Utf8JsonWriter writer, LaborCodeModel value, JsonSerializerOptions options)
writer.WriteStartObject();
foreach(PropertyInfo p in value.GetType().GetProperties())
public class CustomJsonConverter : JsonConverter<CreateLaborCodeRequestModel>
public override CreateLaborCodeRequestModel Read(ref Utf8JsonReader reader, Type type, JsonSerializerOptions options)
throw new NotImplementedException();
public override void Write(Utf8JsonWriter writer, CreateLaborCodeRequestModel value, JsonSerializerOptions options)
foreach(PropertyInfo p in value.GetType().GetProperties())
if(Attribute.IsDefined(p, typeof(IgnorePropertyName)))
writer.WriteRawValue((JsonSerializer.Serialize(p.GetValue(value, null))));
else if(Attribute.IsDefined(p, typeof(RouteParameterAttribute)))
JsonSerializer.Serialize(writer, p.GetValue(value, null));
public class CreateLaborCodeRequestModel
[JsonConverter(typeof(CustomJsonConverterDynamic))]
public LaborCodeModel NewLaborCode { get; }
[RouteParameter("{name}")]
public string Name {get; set;}
public CreateLaborCodeRequestModel(LaborCodeModel laborcode)
NewLaborCode = laborcode;
public class LaborCodeModel
public int LCLevel { get; set; }
public string Code { get; set; }
public string Description { get; set; }
public class IgnorePropertyName : Attribute
public class RouteParameterAttribute : RequestPlaceholderAttribute
public RouteParameterAttribute(string placeholder)
public class RequestPlaceholderAttribute : Attribute
public string Placeholder { get; }
public RequestPlaceholderAttribute(string placeholder)
Placeholder = placeholder;