1 year ago
#73050
hanushi
Result is [ null ] insted of [ ] after changing from JSON.NET to System.Text.Json in ASP.NET Core 6
I am working an ASP.NET Core 6.0 project.
I wrote a query which is related to this property:
public List<Holiday> Holidays { get; set; }
It returns
"holidays": [ null ],
This happens after I change from JSON.NET to System.Text.Json
.
So when using
builder.Services
.AddControllers(options =>
options.Filters.Add<ApiExceptionFilterAttribute>())
.AddFluentValidation()
.AddJsonOptions(options => options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles);
But, when using
builder.Services
.AddControllers(options =>
options.Filters.Add<ApiExceptionFilterAttribute>())
.AddFluentValidation()
.AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);
the same code returns
holidays : []
Why does this happen?
c#
asp.net-core
json.net
system.text.json
asp.net-core-6.0
0 Answers
Your Answer