Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.Net Core - Set JsonApiSerializer as Default Setting

See original GitHub issue

Hello Everyone!!

I am really appreciating this library. Great Job. Maybe this is not the right place to ask, but I really dont know.

I am trying to get a global configuration using .NET CORE 2 MVC API.

I can easily convert an object using this code. This is a controller and I am converting and respond using Ok(Json).

        public IActionResult Get([FromRoute]string company)
            var parts = _partService.GetAll(company);

            string json = JsonConvert.SerializeObject(parts, new JsonApiSerializerSettings());

            return Ok(json);

. It Works, but add some backslashes to the JSON due to the duplicate serialization, from the JsonConvert and then from the MVC.


I Tried to look over the internet and could not find any place where I could change globally the JsonSerializerSettings with NET CORE.

I am thinking there is something related to services.AddMvc().AddJsonOption inside Startup class but I really dont know where to look or how to do it.

Thanks in advance for any help!!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7

github_iconTop GitHub Comments

alex-daviescommented, Jan 12, 2018

Although closed you can achieve something similiar with less lines by going

 services.AddMvc(opt => {
                var jsonApiFormatter = new JsonOutputFormatter(new JsonApiSerializerSettings(), ArrayPool<Char>.Shared);
                opt.OutputFormatters.Insert(0, jsonApiFormatter);
Brunoporto2702commented, Nov 11, 2020

Does Anyone knows how to setup JsonApiSerializer as the default input serializer on .NET 3.1? No matter how hard I try, I can’t get the objects of my Binding Model to be different from null when sending a JsonApi formatted object.


Read more comments on GitHub >

github_iconTop Results From Across the Web

How to setup JsonApiSerializer as default input and output ...
ASP.NET Core 3.1 will use the System.Text.Json serializers by default. The JsonApiSerializer you are attempting to use requires Newtonsoft.
Read more >
How to instantiate JsonSerializerOptions with System.Text. ...
The JsonSerializerOptions constructor lets you create a new instance with the default options that ASP.NET Core uses for web apps, ...
Read more >
Using multiple JSON serialization settings in ASP.NET Core
Named JSON settings ... First, we need a way to specify multiple JSON serialization settings, and access these settings by name. Fortunately, ASP....
Read more >
Override JSON.NET Serialization Settings Back To Default
Head over to our startup.cs and find the ConfigureServices method. In there we should already see a call to AddMvc(), and we are...
Read more >
ASP.NET Core JSON Serialization - Documentation - Telerik
Configure JSON Serialization in ASP.NET Core 3 through ASP.NET Core 5 · The recommended approach is to use the default serialization that is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found