Provide a Way to Override JSON Serializer Options
Is your feature request related to a problem? Please describe. I would like to override the JSON serializer options which seem to be hard coded in HttpResponseExtensions. It would be nice to indent the JSON in dev/test for easier debugging.
Describe the solution you'd like
ASP.NET Core provides a way to override the JSON options e.g. I use this in my Swagger API:
builder.AddJsonOptions(
options =>
{
var jsonSerializerOptions = options.JsonSerializerOptions;
if (webHostEnvironment.IsDevelopment() ||
webHostEnvironment.IsEnvironment("Test"))
{
// Pretty print the JSON in development/test for easier debugging.
jsonSerializerOptions.WriteIndented = true;
}
jsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
jsonSerializerOptions.DictionaryKeyPolicy = JsonNamingPolicy.CamelCase;
jsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
});
do you have any workaround for this ?
I see this was reopened. We really need this in place cause of issues with current serialization using System.Text.Json. We need to switch to Newtonsoft.Json but this limitation is preventing us from doing that. Is there an estimate on when this will be implemented?
I need this feature. The default JSON serializer seems to be stripping out microseconds from datetimes.
This is not really possible as the scalars in GraphQL also define how they translate into JSON or other serialization formats. Also things like casing are very much specified by the GraphQL spec.
However, for version 13 we now allow to specify the indentation options and the JsonEncoder.
services.AddHttpResponseFormatter(indented: true, encoder ....