Skip to content

Provide a Way to Override JSON Serializer Options #4072

@RehanSaeed

Description

@RehanSaeed

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;
    });

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions