This gist shows the various pieces needed to implement System.Text.Json
instead of System.Web.Script.Serialization.JavaScriptSerializer
or Newsonsoft.Json
in ASP.NET MVC 5. We need to make the replacement in two places: the model binding for deserializing requests, and JsonResult
for serializing responses.
For the model binding, implement a custom Value Provider to replace the default JsonValueProviderFactory
.
CustomJsonValueProviderFactory.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;