From 633458a07873f33c42a61969ac5192f8aea5286e Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 15 Jul 2019 15:16:42 -0700 Subject: [PATCH] Avoid throwing if serializer settings is null Also adds some docs that suggest what needs to be passed as an argument instance --- src/Mvc/Mvc.Core/src/JsonResult.cs | 23 +++++++++++++++------- src/Mvc/Mvc.ViewFeatures/src/Controller.cs | 15 ++++++++------ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/Mvc/Mvc.Core/src/JsonResult.cs b/src/Mvc/Mvc.Core/src/JsonResult.cs index c62cf5e49ebd..6d43cc68323e 100644 --- a/src/Mvc/Mvc.Core/src/JsonResult.cs +++ b/src/Mvc/Mvc.Core/src/JsonResult.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Text.Json; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.Core; using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.Extensions.DependencyInjection; @@ -27,14 +27,17 @@ public JsonResult(object value) /// Creates a new with the given . /// /// The value to format as JSON. - /// The serializer settings to be used by the formatter. + /// + /// The serializer settings to be used by the formatter. + /// + /// When using System.Text.Json, this should be an instance of . + /// + /// + /// When using Newtonsoft.Json, this should be an instance of JsonSerializerSettings. + /// + /// public JsonResult(object value, object serializerSettings) { - if (serializerSettings == null) - { - throw new ArgumentNullException(nameof(serializerSettings)); - } - Value = value; SerializerSettings = serializerSettings; } @@ -46,6 +49,12 @@ public JsonResult(object value, object serializerSettings) /// /// Gets or sets the serializer settings. + /// + /// When using System.Text.Json, this should be an instance of + /// + /// + /// When using Newtonsoft.Json, this should be an instance of JsonSerializerSettings. + /// /// public object SerializerSettings { get; set; } diff --git a/src/Mvc/Mvc.ViewFeatures/src/Controller.cs b/src/Mvc/Mvc.ViewFeatures/src/Controller.cs index e90117df62b2..0171f04797f5 100644 --- a/src/Mvc/Mvc.ViewFeatures/src/Controller.cs +++ b/src/Mvc/Mvc.ViewFeatures/src/Controller.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.Text.Json; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.ModelBinding; @@ -298,7 +299,14 @@ public virtual JsonResult Json(object data) /// to JSON. /// /// The object to serialize. - /// The serializer settings to be used by the formatter. + /// The serializer settings to be used by the formatter. + /// + /// When using System.Text.Json, this should be an instance of . + /// + /// + /// When using Newtonsoft.Json, this should be an instance of JsonSerializerSettings. + /// + /// /// The created that serializes the specified /// as JSON format for the response. /// Callers should cache an instance of serializer settings to avoid @@ -306,11 +314,6 @@ public virtual JsonResult Json(object data) [NonAction] public virtual JsonResult Json(object data, object serializerSettings) { - if (serializerSettings == null) - { - throw new ArgumentNullException(nameof(serializerSettings)); - } - return new JsonResult(data, serializerSettings); }