diff --git a/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Internal/JsonResultExecutor.cs b/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Internal/JsonResultExecutor.cs index a0e12cfd94..5a00321635 100644 --- a/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Internal/JsonResultExecutor.cs +++ b/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Internal/JsonResultExecutor.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Buffers; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Internal; @@ -22,6 +23,8 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Json.Internal Encoding = Encoding.UTF8 }.ToString(); + private readonly IArrayPool _charPool; + /// /// Creates a new . /// @@ -31,7 +34,8 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Json.Internal public JsonResultExecutor( IHttpResponseStreamWriterFactory writerFactory, ILogger logger, - IOptions options) + IOptions options, + ArrayPool charPool) { if (writerFactory == null) { @@ -48,9 +52,15 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Json.Internal throw new ArgumentNullException(nameof(options)); } + if (charPool == null) + { + throw new ArgumentNullException(nameof(charPool)); + } + WriterFactory = writerFactory; Logger = logger; Options = options.Value; + _charPool = new JsonArrayPool(charPool); } /// @@ -111,6 +121,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Json.Internal { using (var jsonWriter = new JsonTextWriter(writer)) { + jsonWriter.ArrayPool = _charPool; jsonWriter.CloseOutput = false; var jsonSerializer = JsonSerializer.Create(serializerSettings); diff --git a/test/Microsoft.AspNetCore.Mvc.Formatters.Json.Test/Internal/JsonResultExecutorTest.cs b/test/Microsoft.AspNetCore.Mvc.Formatters.Json.Test/Internal/JsonResultExecutorTest.cs index 8de07601a7..ecd9bef6ff 100644 --- a/test/Microsoft.AspNetCore.Mvc.Formatters.Json.Test/Internal/JsonResultExecutorTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Formatters.Json.Test/Internal/JsonResultExecutorTest.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Buffers; using System.IO; using System.Text; using System.Threading.Tasks; @@ -161,7 +162,8 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Json.Internal return new JsonResultExecutor( new TestHttpResponseStreamWriterFactory(), NullLogger.Instance, - new TestOptionsManager()); + new TestOptionsManager(), + ArrayPool.Shared); } private static HttpContext GetHttpContext() diff --git a/test/Microsoft.AspNetCore.Mvc.Formatters.Json.Test/JsonResultTest.cs b/test/Microsoft.AspNetCore.Mvc.Formatters.Json.Test/JsonResultTest.cs index 1d35d1cffd..89b84cdba8 100644 --- a/test/Microsoft.AspNetCore.Mvc.Formatters.Json.Test/JsonResultTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Formatters.Json.Test/JsonResultTest.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Buffers; using System.IO; using System.Text; using System.Threading.Tasks; @@ -46,7 +47,8 @@ namespace Microsoft.AspNetCore.Mvc var executor = new JsonResultExecutor( new TestHttpResponseStreamWriterFactory(), NullLogger.Instance, - new TestOptionsManager()); + new TestOptionsManager(), + ArrayPool.Shared); var services = new ServiceCollection(); services.AddSingleton(executor);