Skip to main content
deleted 93 characters in body
Source Link
b.m
  • 1.7k
  • 20
  • 19

With asp.net core 3With asp.net core 3

using System.Text.Json.Serialization;
        
public class Startup
{
        public void ConfigureServices(IServiceCollection services)
        {
              services.AddControllers().AddJsonOptions(options =>
              {
                  options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
                  options.JsonSerializerOptions.IgnoreNullValues = true;
              });

But it seems that Swashbuckle Version 5.0.0-rc4 is not ready to support that. So we need to add a dipricateduse an option to(deprecated) in the Swashbuckle config file until it supportsupports and reflectreflects it like Newtonsoft library.

public void ConfigureServices(IServiceCollection services)
{ 
      services.AddSwaggerGen(c =>
      {
            c.DescribeAllEnumsAsStrings();

The difference between this answer and other answers is using only the Microsoft JSON library instead of Newtonsoft.

With asp.net core 3

using System.Text.Json.Serialization;

public class Startup
{
        public void ConfigureServices(IServiceCollection services)
        {
              services.AddControllers().AddJsonOptions(options =>
              {
                  options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
                  options.JsonSerializerOptions.IgnoreNullValues = true;
              });

But it seems that Swashbuckle Version 5.0.0-rc4 is not ready to support that. So we need to add a dipricated option to Swashbuckle config file until it support and reflect it.

public void ConfigureServices(IServiceCollection services)
{ 
      services.AddSwaggerGen(c =>
      {
            c.DescribeAllEnumsAsStrings();

The difference between this answer and other answers is using only the Microsoft JSON library instead of Newtonsoft.

With asp.net core 3

using System.Text.Json.Serialization;
        
public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
         services.AddControllers().AddJsonOptions(options =>
             options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()));

But it seems that Swashbuckle Version 5.0.0-rc4 is not ready to support that. So we need to use an option(deprecated) in the Swashbuckle config file until it supports and reflects it like Newtonsoft library.

public void ConfigureServices(IServiceCollection services)
{ 
      services.AddSwaggerGen(c =>
      {
            c.DescribeAllEnumsAsStrings();

The difference between this answer and other answers is using only the Microsoft JSON library instead of Newtonsoft.

Source Link
b.m
  • 1.7k
  • 20
  • 19

With asp.net core 3

using System.Text.Json.Serialization;

public class Startup
{
        public void ConfigureServices(IServiceCollection services)
        {
              services.AddControllers().AddJsonOptions(options =>
              {
                  options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
                  options.JsonSerializerOptions.IgnoreNullValues = true;
              });

But it seems that Swashbuckle Version 5.0.0-rc4 is not ready to support that. So we need to add a dipricated option to Swashbuckle config file until it support and reflect it.

public void ConfigureServices(IServiceCollection services)
{ 
      services.AddSwaggerGen(c =>
      {
            c.DescribeAllEnumsAsStrings();

The difference between this answer and other answers is using only the Microsoft JSON library instead of Newtonsoft.