parent
29646153ea
commit
7cb1dca467
|
|
@ -212,7 +212,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
|
||||||
{
|
{
|
||||||
if (_jsonSerializerPool == null)
|
if (_jsonSerializerPool == null)
|
||||||
{
|
{
|
||||||
_jsonSerializerPool = _objectPoolProvider.Create<JsonSerializer>();
|
_jsonSerializerPool = _objectPoolProvider.Create(new JsonSerializerObjectPolicy(SerializerSettings));
|
||||||
}
|
}
|
||||||
|
|
||||||
return _jsonSerializerPool.Get();
|
return _jsonSerializerPool.Get();
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata;
|
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Logging.Testing;
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
|
@ -21,7 +20,6 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
|
||||||
{
|
{
|
||||||
public class JsonInputFormatterTest
|
public class JsonInputFormatterTest
|
||||||
{
|
{
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("application/json", true)]
|
[InlineData("application/json", true)]
|
||||||
[InlineData("application/*", false)]
|
[InlineData("application/*", false)]
|
||||||
|
|
@ -358,6 +356,37 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
|
||||||
Assert.Contains("Required property 'Password' not found in JSON", modelErrorMessage);
|
Assert.Contains("Required property 'Password' not found in JSON", modelErrorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CreateJsonSerializer_UsesJsonSerializerSettings()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var settings = new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
ContractResolver = Mock.Of<IContractResolver>(),
|
||||||
|
MaxDepth = 2,
|
||||||
|
DateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind,
|
||||||
|
};
|
||||||
|
var formatter = new TestableJsonInputFormatter(GetLogger(), settings);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var actual = formatter.CreateJsonSerializer();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Same(settings.ContractResolver, actual.ContractResolver);
|
||||||
|
Assert.Equal(settings.MaxDepth, actual.MaxDepth);
|
||||||
|
Assert.Equal(settings.DateTimeZoneHandling, actual.DateTimeZoneHandling);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TestableJsonInputFormatter : JsonInputFormatter
|
||||||
|
{
|
||||||
|
public TestableJsonInputFormatter(ILogger logger, JsonSerializerSettings settings)
|
||||||
|
: base(logger, settings)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public new JsonSerializer CreateJsonSerializer() => base.CreateJsonSerializer();
|
||||||
|
}
|
||||||
|
|
||||||
private static ILogger GetLogger()
|
private static ILogger GetLogger()
|
||||||
{
|
{
|
||||||
return NullLogger.Instance;
|
return NullLogger.Instance;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue