In my ASP.NET Core app, I have the following setup in Startup
:
services.AddNewtonsoftJson(options =>
{
options.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
options.SerializerSettings.DateFormatString = "yyyy/MM/dd"; // <-- HERE
});
The line marked with "HERE" comment sets a global way of handling DateTime
serialization. This is what I need in 99% of the cases. However, I have an endpoint where I do not want to format dates this way and I want to retain time information as well (in ISO format for example). Is there any way to override the global setting somehow for specific endpoint or model?
I tried applying [JsonConverter(typeof(IsoDateTimeConverter))]
attribute to my model's DateTime
properties, but that didn't change anything.