0

I use .NET 7 Minimal API (app.MapGet) but I can't figure out how to use Newtonsoft instead of System.Text.Json.

I tried...

builder.Services.AddMvc().AddNewtonsoftJson();

And also...

builder.Services.AddControllersWithViews() .AddNewtonsoftJson(options => options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver());

.. but since I have no controllers, it doesn't seam to work.

Guru Stron
  • 102,774
  • 10
  • 95
  • 132
MojoDK
  • 4,410
  • 10
  • 42
  • 80
  • 1
    In addition to the suggested duplicate, the [documentation](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis?view=aspnetcore-7.0#customize-json-binding) says "The body binding source uses System.Text.Json for de-serialization. It is not possible to change this default" – gunr2171 Mar 13 '23 at 21:16
  • For what it's worth, I think the hype around minimal apis for anything other than happy path feature-sets isn't worth the cost. If you need to do something with lots of configuration, just use the standard api. It's really not that much extra work. – David L Mar 13 '23 at 21:46

0 Answers0