Skip to content

Commit

Permalink
make NewtonsoftJson and System.Text.Json works side by side (fixed) (#…
Browse files Browse the repository at this point in the history
…4441)

* make NewtonsoftJson and System.Text.Json works side by side.
The idea is instead of using AddNewtonsoftJson to all controllers,make an attribute to use Newtensoft as Object result's formatter, and apply this attribute to all controllers that in Elsa.Server.Api namespace.

* update

* update
  • Loading branch information
liuliang-wt committed Sep 15, 2023
1 parent db847f9 commit f9be19a
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public override void OnActionExecuted(ActionExecutedContext context)
objectResult.Formatters.Add(new NewtonsoftJsonOutputFormatter(
jsonSettings,
context.HttpContext.RequestServices.GetRequiredService<ArrayPool<char>>(),
context.HttpContext.RequestServices.GetRequiredService<IOptions<MvcOptions>>().Value,
context.HttpContext.RequestServices.GetRequiredService<IOptions<MvcNewtonsoftJsonOptions>>().Value));
context.HttpContext.RequestServices.GetRequiredService<IOptions<MvcOptions>>().Value));

}
//For JsonResult, there is no way to change the formatter, so change them to Object result
else if (context.Result is JsonResult jr)
Expand All @@ -84,8 +84,8 @@ public override void OnActionExecuted(ActionExecutedContext context)
obj.Formatters.Add(new NewtonsoftJsonOutputFormatter(
jsonSettings,
context.HttpContext.RequestServices.GetRequiredService<ArrayPool<char>>(),
context.HttpContext.RequestServices.GetRequiredService<IOptions<MvcOptions>>().Value,
context.HttpContext.RequestServices.GetRequiredService<IOptions<MvcNewtonsoftJsonOptions>>().Value));
context.HttpContext.RequestServices.GetRequiredService<IOptions<MvcOptions>>().Value));

context.Result = obj;
}
else
Expand Down

0 comments on commit f9be19a

Please sign in to comment.