title: Swashbuckle.AspNetCore.Filters throws an exception when trying to use System.Text.Json.Serialization.JsonStringEnumConverter
body: <p>I've an ASP.NET Core 3.1 project on which I want to generate the API documentation along with queryable examples using Swagger.</p>
  
  <p>I want to use the new <code>System.Text.Json</code> namespace instead of the good old <code>Newtonsoft.Json</code> one</p>
  
  <p>As stated in the <a href="https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/master/README.md#systemtextjson-stj-vs-newtonsoft" rel="nofollow noreferrer">Swagger documentation</a></p>
  
  <blockquote>
    <p>If you're using System.Text.Json (STJ), then the setup described above will be sufficient, and STJ options/attributes will be automatically honored by the Swagger generator</p>
    
    <p>If you're using Newtonsoft, then you'll need to install a separate package and explicitly opt-in to ensure that Newtonsoft settings/attributes are automatically honored by the Swagger generator</p>
  </blockquote>
  
  <p>I did <strong>NOT</strong> install the <code>Swashbuckle.AspNetCore.Newtonsoft</code> package and I did <strong>NOT</strong> call <code>services.AddSwaggerGenNewtonsoftSupport()</code>.</p>
  
  <p>My controller's method looks like this (I want to convert Enums to string values instead of integers)</p>
  
  <pre class="lang-cs prettyprint-override"><code>/// &lt;summary&gt;
  /// Just a test Method
  /// &lt;/summary&gt;
  /// &lt;param name="fooParams"&gt;My Params&lt;/param&gt;
  /// &lt;returns&gt;&lt;/returns&gt;
  [HttpGet("Foo")]
  [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(FooResult))]
  [SwaggerRequestExample(requestType: typeof(FooQuery), examplesProviderType: typeof(FooRequestExampleProvider), jsonConverter: typeof(System.Text.Json.Serialization.JsonStringEnumConverter))]
  [SwaggerResponseExample(statusCode: 200, examplesProviderType: typeof(FooResponseExampleProvider), jsonConverter: typeof(System.Text.Json.Serialization.JsonStringEnumConverter))]
  public FooResult Foo([FromQuery]FooQuery fooParams)
  {
      return _processor.Execute&lt;FooQuery, FooResult&gt;(fooParams);
  }
  </code></pre>
  
  <p>However when I execute this method (called in my <code>Startup.cs</code>)</p>
  
  <pre class="lang-cs prettyprint-override"><code>public static IApplicationBuilder UseVersionedSwagger(this IApplicationBuilder app, IApiVersionDescriptionProvider provider)
  {
      app.UseSwagger();
  
      app.UseSwaggerUI(options =&gt;
      {
          foreach (var description in provider.ApiVersionDescriptions)
          {
              options.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json", description.GroupName.ToUpperInvariant());
          }
      });
  
      return app;
  }
  </code></pre>
  
  <p>I get an exception saying </p>
  
  <blockquote>
    <p>System.InvalidCastException</p>
    
    <p>HResult=0x80004002</p>
    
    <p>Message=Unable to cast object of type 'System.Text.Json.Serialization.JsonStringEnumConverter' to type 'Newtonsoft.Json.JsonConverter'.
      Source=Swashbuckle.AspNetCore.Filters</p>
  </blockquote>
  
  <p>Here is the packages I reference in my <code>.csproj</code></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;PackageReference Include="FluentValidation.AspNetCore" Version="8.6.1" /&gt;
  &lt;PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="4.1.1" /&gt;
  &lt;PackageReference Include="Microsoft.Extensions.ApiDescription.Server" Version="3.1.0"&gt;
    &lt;PrivateAssets&gt;all&lt;/PrivateAssets&gt;
    &lt;IncludeAssets&gt;runtime; build; native; contentfiles; analyzers; buildtransitive&lt;/IncludeAssets&gt;
  &lt;/PackageReference&gt;
  &lt;PackageReference Include="Rebus.RabbitMq" Version="5.2.0" /&gt;
  &lt;PackageReference Include="SimpleInjector.Integration.AspNetCore.Mvc" Version="4.8.1" /&gt;
  &lt;PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc5" /&gt;
  &lt;PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="5.0.0-rc9" /&gt;
  &lt;PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="5.0.0-rc5" /&gt;
  &lt;PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="5.0.0-rc5" /&gt;
  &lt;PackageReference Include="Swashbuckle.AspNetCore.SwaggerUi" Version="5.0.0-rc5" /&gt;
  </code></pre>
  
  <p>If I change my controller's method to use <code>Newtonsoft.Json</code> it works well, no exception</p>
  
  <pre class="lang-cs prettyprint-override"><code>/// &lt;summary&gt;
  /// Just a test Method
  /// &lt;/summary&gt;
  /// &lt;param name="fooParams"&gt;My Params&lt;/param&gt;
  /// &lt;returns&gt;&lt;/returns&gt;
  [HttpGet("Foo")]
  [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(FooResult))]
  [SwaggerRequestExample(requestType: typeof(FooQuery), examplesProviderType: typeof(FooRequestExampleProvider), jsonConverter: typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
  [[SwaggerResponseExample(statusCode: 200, examplesProviderType: typeof(FooResponseExampleProvider), jsonConverter: typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
  public FooResult Foo([FromQuery]FooQuery fooParams)
  {
      return _processor.Execute&lt;FooQuery, FooResult&gt;(fooParams);
  }
  </code></pre>
  
  <p>I even tried to explicitly specify this in my <code>Startup.cs</code></p>
  
  <pre class="lang-cs prettyprint-override"><code>services.AddControllers()
      .AddJsonOptions(options =&gt;
      {
          options.JsonSerializerOptions.Converters.Add(new System.Text.Json.Serialization.JsonStringEnumConverter());
      });
  </code></pre>
  
  <p>But still I'm not able to use <code>System.Text.Json.Serialization.JsonStringEnumConverter</code>, only <code>Newtonsoft.Json.Converters.StringEnumConverter</code> works.</p>
  
  <p>Here is my <code>FooQuery</code> class which contains a <code>FooEnum</code> property that I want to convert to string values in Swagger</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class FooQuery
  {
      public string Code { get; set; }
  
      public FooEnum MyFooParam { get; set; }
  }
  </code></pre>
  
  <p>So is my code incorrect somewhere? Did I miss something? </p>
  
  <p>Or is it a problem with the <code>Swashbuckle.AspNetCore.Filters</code> package? Is the version <code>5.0.0-rc9</code> of this package buggy and not yet compatible with <code>System.Text.Json.Serialization.JsonStringEnumConverter</code>?</p>
  
  <p>Thanks for your answers</p>