Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Add a Controller.Json(object, JsonSerializerSettings) overload #2506

Closed
@JamesNK

Description

@JamesNK

Right now JSON settings can only be defined once at an application level on the JsonOutputFormatter. It would be useful to be able to pass a JsonSerializerSettings argument to the Controller.Json method to override the JSON settings on a per result basis, e.g. a developer might want indented JSON, or to use a specific JsonConverter, for only one action in their application.

Current method:

/// <summary>
/// Creates a <see cref="JsonResult"/> object that serializes the specified <paramref name="data"/> object
/// to JSON.
/// </summary>
/// <param name="data">The object to serialize.</param>
/// <returns>The created <see cref="JsonResult"/> that serializes the specified <paramref name="data"/>
/// to JSON format for the response.</returns>
[NonAction]
public virtual JsonResult Json(object data)
{
var disposableValue = data as IDisposable;
if (disposableValue != null)
{
Response.OnResponseCompleted(_ => disposableValue.Dispose(), state: null);
}
return new JsonResult(data);
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions