using System; using System.Text.Json; using System.Text.Json.Serialization; using Znyc.Recruitment.Admin.Commons.Extensions; namespace Znyc.Recruitment.Admin.Commons.Helpers { public class DecimalJsonConverter : JsonConverter { /// /// /// /// /// /// public override decimal Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { if (reader.TokenType == JsonTokenType.Number) { return reader.GetDecimal(); } return reader.GetString().Equals("") ? "0.00".ToDecimal() : reader.GetString().ToDecimal(); } /// /// /// /// /// public override void Write(Utf8JsonWriter writer, decimal value, JsonSerializerOptions options) { writer.WriteNumberValue(value); } } }