JsonIgnore Not Work With Swagger When Using NewtonSoft

net core 5, I stopped using System.text.Json for some reason and I use NewtonSoft and I changed all the namespaces, for example, to JsonIgnore, but my problem is that the properties that I ignored are still displayed in the swagger output.

 using System;
 using Newtonsoft.Json;
 public class AddEmployeeDto
    public Guid Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }

    public int EmployeeType { get; set; }

this is swagger output :

enter image description here

>Solution :

Since Sytem.text.Json has become the default Serialize tool of Asp.Net Core, the standard version of Swagger is also compatible with it,
and to change it, like this change that you have probably applied,

You must install the package From Nuget:


And register it in your Service Container as follows to solve your problem


Leave a Reply