Add formatter mapping for JSON (#12592)

Fixes https://github.com/aspnet/AspNetCore/issues/12414
This commit is contained in:
Pranav K 2019-07-25 16:50:54 -07:00 committed by GitHub
parent b13f2614de
commit d7bfbb5824
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -80,6 +80,9 @@ namespace Microsoft.AspNetCore.Mvc
// Set up default input formatters.
options.InputFormatters.Add(new SystemTextJsonInputFormatter(_jsonOptions.Value, _loggerFactory.CreateLogger<SystemTextJsonInputFormatter>()));
// Media type formatter mappings for JSON
options.FormatterMappings.SetMediaTypeMappingForFormat("json", MediaTypeHeaderValues.ApplicationJson);
// Set up default output formatters.
options.OutputFormatters.Add(new HttpNoContentOutputFormatter());
options.OutputFormatters.Add(new StringOutputFormatter());

View File

@ -111,6 +111,17 @@ namespace Microsoft.AspNetCore.Mvc
formatter => Assert.IsType<SystemTextJsonInputFormatter>(formatter));
}
[Fact]
public void Setup_SetsUpFormatterMapping()
{
// Arrange & Act
var options = GetOptions<MvcOptions>();
// Assert
var mapping = options.FormatterMappings.GetMediaTypeMappingForFormat("json");
Assert.Equal("application/json", mapping);
}
[Fact]
public void Setup_SetsUpModelValidatorProviders()
{