I have an ASPNet API server using EF Core 6, and when I use WriteAsJsonAsync
to write a decimal property it becomes like: "decimal_property": 0.0000000000000000000000000000
. I don't want to trailing zeros.
I found some solutions of custom converts, but they are all written in Newtonsoft
rather than System.Text.Json
so cannot be used like
builder.Services.Configure<JsonOptions>(opt =>
{
opt.SerializerOptions.Converters.Add(new DecimalJsonConverter());
}
How to write a DecimalJsonConverter
can be injected into WebApplication
directly?