Skip to content

Latest commit

 

History

History
47 lines (40 loc) · 1.75 KB

output-formatters-serialization.md

File metadata and controls

47 lines (40 loc) · 1.75 KB

Output formatters

Available starting with v1.9.0

Enabling output formatters support is a matter of:

public void ConfigureServices(IServiceCollection services)
{
    services.AddViewModelComposition(options =>
    {
        options.ResponseSerialization.UseOutputFormatters = true;
    });
    services.AddControllers();
}

snippet source | anchor

The required steps are:

  • set UseOutputFormatters to true
  • Set up the MVC components by calling one of the following:
    • AddControllers()
    • AddControllersAndViews()
    • AddMvc
    • AddRazorPages()

The above configuration uses the new System.Text.Json serializer as the default json serializer to format json responses. It's possible to plug-in the Newtonsoft Json.Net serializer output formatter by adding a package reference to the Microsoft.AspNetCore.Mvc.NewtonsoftJson package, and using the following configuration:

public void ConfigureServices(IServiceCollection services)
{
    services.AddViewModelComposition(options =>
    {
        options.ResponseSerialization.UseOutputFormatters = true;
    });
    services.AddControllers()
        .AddNewtonsoftJson();
}

snippet source | anchor