using System.Collections.Generic;
using System.Text.Json.Serialization;
private const string JsonString = @"
""serialNo"": ""000000000002200878"",
""affiliationOrgCode"": ""OrgCode1""
""serialNo"": ""000000000002201675"",
""affiliationOrgCode"": ""OrgCode1""
public static void Main()
var options = new JsonSerializerOptions(JsonSerializerDefaults.Web);
options.Converters.Add(new SerialNoConverter());
var deserializedClass = JsonSerializer.Deserialize<Root>(JsonString, options);
deserializedClass.Dump();
public class SerialNoConverter : JsonConverter<SerialNo>
public override SerialNo? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
var serialNo = reader.GetString();
return new SerialNo(serialNo);
public override void Write(Utf8JsonWriter writer, SerialNo value, JsonSerializerOptions options)
throw new NotImplementedException();
public SerialNo(string serialNo)
if (serialNo == null) throw new ArgumentNullException(nameof(serialNo));
if (string.IsNullOrWhiteSpace(serialNo)) throw new Exception("My exception text");
Value = serialNo.Trim('0');
[JsonPropertyName("serialNo")]
public string Value { get; set; }
public SerialNo SerialNo { get; set; }
public string AffiliationOrgCode { get; set; }
public List<Item> Item { get; set; }