Recently I have decided to go from ASP.NET Core 2.2 to ASP.NET Core 3.1 and did not anticipate all the breaking changes; nearly every part of my application broke as most parts rely on JSON.
To safeguard against future JSON related problems, would it be possible to create an interface, mimicking the current Json implementation and override the default behaviour.
Most of my code relies on these two methods:
Json.Serialize() // used in my razor
Json() // returns an IActionResult
Use case: a Razor Page : Json.Serialize Doc
<script>
var myModel = @Html.Raw(Json.Serialize(Model))
</script>
Use case: a Controller
public async Task<IActionResult> AjaxGetRoleDetails(int id)
{
return Json(await GetUserRoles(id));
}
Here are the methods that I would like, when the above methods are called respectively.
JsonConvert.SerializeObject() // override Json.Serialize
Content(JsonConvert.SerializeObject(), new MediaTypeHeaderValue("application/json")) // override Json()
How can override the system implementation, and call my own implementation for now, and later easily revert to the system's implementation when ASP.NET settles on a JSON implementation.