Skip to content

Instantly share code, notes, and snippets.

Avatar
🥲

Jacob Stamm stamminator

🥲
  • Security 101
  • South Florida
View GitHub Profile
@stamminator
stamminator / README.md
Last active Feb 4, 2022
Using System.Text.Json serialization in ASP.NET MVC 5
View README.md

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;