From f9be19a6102618311bbb35f9b6cee41c84afdd63 Mon Sep 17 00:00:00 2001 From: liuliang-wt Date: Fri, 15 Sep 2023 17:19:15 +0800 Subject: [PATCH] make NewtonsoftJson and System.Text.Json works side by side (fixed) (#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 --- .../Attributes/NewtonsoftJsonFormatterAttribute.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/server/Elsa.Server.Api/Attributes/NewtonsoftJsonFormatterAttribute.cs b/src/server/Elsa.Server.Api/Attributes/NewtonsoftJsonFormatterAttribute.cs index 6d77c41ce1..41fc314808 100644 --- a/src/server/Elsa.Server.Api/Attributes/NewtonsoftJsonFormatterAttribute.cs +++ b/src/server/Elsa.Server.Api/Attributes/NewtonsoftJsonFormatterAttribute.cs @@ -72,8 +72,8 @@ public override void OnActionExecuted(ActionExecutedContext context) objectResult.Formatters.Add(new NewtonsoftJsonOutputFormatter( jsonSettings, context.HttpContext.RequestServices.GetRequiredService>(), - context.HttpContext.RequestServices.GetRequiredService>().Value, - context.HttpContext.RequestServices.GetRequiredService>().Value)); + context.HttpContext.RequestServices.GetRequiredService>().Value)); + } //For JsonResult, there is no way to change the formatter, so change them to Object result else if (context.Result is JsonResult jr) @@ -84,8 +84,8 @@ public override void OnActionExecuted(ActionExecutedContext context) obj.Formatters.Add(new NewtonsoftJsonOutputFormatter( jsonSettings, context.HttpContext.RequestServices.GetRequiredService>(), - context.HttpContext.RequestServices.GetRequiredService>().Value, - context.HttpContext.RequestServices.GetRequiredService>().Value)); + context.HttpContext.RequestServices.GetRequiredService>().Value)); + context.Result = obj; } else