DateOnlyTimeOnly.AspNet icon indicating copy to clipboard operation
DateOnlyTimeOnly.AspNet copied to clipboard

It's impossible to use DateOnly in the Dictionaries

Open veonua opened this issue 3 years ago • 1 comments

The type 'System.DateOnly' is not a supported dictionary key using converter of type 'DateOnlyTimeOnly.AspNet.Converters.DateOnlyJsonConverter'.

[HttpGet]
[Route("date-foo")]
public async Task<Dictionary<DateOnly, Foo>> GetDatedFoos() {
{
  return results.ToDictionary(x=> x.date, x=> x.foo);
}

veonua avatar Aug 05 '22 09:08 veonua

I think, that's the limitation of System.Text.Json serializer: https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-supported-collection-types?pivots=dotnet-6-0#supported-key-types

But I'll take a look if I can do anything about it.

maxkoshevoi avatar Aug 05 '22 09:08 maxkoshevoi

Had some time today. Turns out, .Net 7 (RC2) actually supports DateTime and DateOnly (but interestingly not TimeOnly) as Dictionary key. Will work on adding it to this package.

image image image

maxkoshevoi avatar Oct 27 '22 20:10 maxkoshevoi

thank you, Max

veonua avatar Oct 27 '22 20:10 veonua

@veonua @ibiza240 You can try version 2.0.0-preview.1, it should be fixed there

maxkoshevoi avatar Oct 27 '22 22:10 maxkoshevoi