title: DateOnly Json Conversion in .net6 api
body: <p><strong>tl;dr:</strong>
  How can I add the DateOnly JsonConverter to the application configuration of a .net6 web api?</p>
  <p>I have an object with DateOnly properties on it and I'm returning it from the controller. When I make my request I get the error &quot;Serialization and deserialization of 'System.DateOnly' instances are not supported&quot;.</p>
  <p>I understand there are limitations with de/serialization of DateOnly and TimeOnly in .net6 (<a href="https://github.com/dotnet/runtime/issues/53539" rel="noreferrer">https://github.com/dotnet/runtime/issues/53539</a>) and I followed the recommended use of a custom JsonConverter. However the problem I am having is where I initialize the converter.</p>
  <p>I tried adding the converter in the web application builder....</p>
  <pre><code>
  builder.Services
      .AddControllers()
      .AddJsonOptions(options =&gt; options.JsonSerializerOptions.Converters.Add(new DateOnlyConverter()));
  </code></pre>
  <p>but no luck.</p>
  <p>Then I tried configuring it specifically</p>
  <pre><code>builder.Services.Configure&lt;JsonSerializerOptions&gt;(options =&gt;
      options.Converters.Add(new DateOnlyConverter()));
  </code></pre>
  <p>no luck there either.</p>
  <p>So I tried returning Results.Json from the controller with the converter in the options <code>Results.Json(status, options)</code>. Even that did not work.</p>
  <p>What did work though was adding an attribute directly to the property</p>
  <pre><code>[property: JsonConverter(typeof(DateOnlyConverter))]
      DateOnly DateOrdered,
  </code></pre>
  <p>I would rather not have to add this attribute to every use of DateOnly and am really unclear as to what is preventing the converter from being called when it's configured as part of WebApplication.
  I've done similar things in .net5 applications, and assume some nuance between IHostBuilder and  WebApplicationBuilder could be causing the issue.</p>
  <p>Edit:
  It's probably worth noting I am using the new minimal apis. But even Microsoft points out Json serialization is configurable <a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis?view=aspnetcore-6.0#customize-json-binding" rel="noreferrer">in the docs here</a>. The docs show slightly different syntax than what is commonly used, <code>builder.Services.Configure&lt;JsonOptions&gt;</code>, so I assumed maybe this was the problem. Perhaps the minimal apis had configuration handled differently. But not so. At least, using the suggested configuration in the minimal api docs did not solve the problem.</p>