-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add a Controller.Json(object, JsonSerializerSettings) overload #2506
Comments
That migh actually be pretty nice |
Would be pretty easy for us to add. Should probably do because WebAPI had something similar:
|
Using |
@henkmollema That overload doesn't stop the underlying JSON formatter being something other than Json.NET - another serializer can ignore that class or read settings from JsonSerializerSettings and map them to its own functionality. To use WebAPI as a similar example, just because WebAPI knew about Json.NET didn't mean you couldn't replace the serializer with SimpleJson. Many people wrote their own WebAPI JSON formatters. |
@JamesNK good point. Was just curious because ASP.NET 5 is all about abstractions and loose coupling. Figured a |
@henkmollema - we're pretty fully-bought into Json.Net at this point. You could use another serializer with MVC/WebAPI if you wanted to, but we don't plan to show an experience where Json.Net isn't a required dependency. |
@rynowak I see, thanks! 😄 |
Was this only added to Core, and not to MVC 5? |
@nicholasyin yes. |
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:
Mvc/src/Microsoft.AspNet.Mvc.Core/Controller.cs
Lines 383 to 400 in 7e62325
The text was updated successfully, but these errors were encountered: