I've been looking around the internet for an answer or example, but could not find one yet. I simply would like to change the default JSON serializer which is used to deserialize JSON while modelbinding to JSON.NET library.
I've found this SO post, but cannot implement it so far, I can't even see the System.Net.Http.Formatters
namespace, nor can I see GlobalConfiguration
.
What am I missing?
UPDATE
I have an ASP.NET MVC project, it was basically an MVC3 project. Currently I'm targetting .NET 4.5 and using the ASP.NET MVC 5 and related NuGet packages.
I don't see the System.Web.Http assembly, nor any similar namespace. In this context I would like to inject JSON.NET to be used as the default model binder for JSON type of requests.
Best Answer
I've finally found an answer. Basically I don't need the
MediaTypeFormatter
stuff, that's not designed to be used in MVC environment, but in ASP.NET Web APIs, that's why I do not see those references and namespaces (by the way, those are included in theMicrosoft.AspNet.WeApi
NuGet package).The solution is to use a custom value provider factory. Here is the code required.
And you can use it like this in your
Application_Start
method:Here is the post which pointed me to the right direction, and also this one gave a good explanation on value providers and modelbinders.