I have an ASP.NET Core 3.1 application where I use
services.AddControllers().AddNewtonsoftJson();
to use the Newtonsoft JSON serializer. Unfortunately I cannot switch completely to System.Text.Json in one step.
Is there a way to put an attribute like
[NewtonsoftJson]
public class MyController : Controller
{
// ...
on those controllers that I could not yet migrate -- and only use Newtonsoft for these controllers?
According to your description, I suggest you could consider using the ActionFilterAttribute to achieve your requirement.
Like below :
More details, you could refer to this article.