question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DateOnly in .net 6 causes indexing error, add support for it

See original GitHub issue

Is your feature request related to a problem? Please describe. Trying to index an object with DateOnly wil cause the following error:

Failed to index document 618252e5fd34fc54f4d94ac3: Type: mapper_parsing_exception Reason: “failed to parse field [dueAt.dayOfWeek] of type [integer] in document with id ‘618252e5fd34fc54f4d94ac3’. Preview of field’s value: ‘Friday’” CausedBy: “Type: number_format_exception Reason: “For input string: “Friday”””

Describe the solution you’d like Proper support for DateOnly, aka a working serializer and deserializer.

Describe alternatives you’ve considered Some custom serializer, but don’t know how to implement this.

Additional context

Settings:

var settings = new ConnectionSettings(pool, (builtin, settings) => new JsonNetSerializer(builtin, settings,
            contractJsonConverters: new JsonConverter[] {new StringEnumConverter()})).EnableDebugMode();

StringEnumConverter seems to break support for DateOnly.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
stevejgordoncommented, Jul 12, 2022

@niemyjski Adding a specific NET6.0 target for 7.x is not going to a priority while we work on v8. I did take a spike on that a while back and ran into some issues, although I need to revisit what those issues where. Given that, as you note, even STJ doesn’t yet support these new DateOnly and TimeOnly types, our general advice is to avoid them on source types. For 8.x we’ll likely be able to support those with the STJ library. One the benefits of the move to STJ as the default source serializer is that custom converters work OOB and provide more standard ways to control advanced serialization.

Thanks for linking to the Newtonsoft PR. Good to see support coming there soon. Once supported there, a workaround would be to use our NewtonsoftJson package to gain support that way. You could also add in a custom ISerializer as a current workaround with a serializer that supports these types. Implementing ISerializer is the intended way for consumers to “extend” the client to support any behaviour for source serialization that is required.

0reactions
stevejgordoncommented, Jul 28, 2022

@sjd2021 It’s been added for .NET 7.0 which is not yet released and supported until November. Our new client targets STJ so consumers will be able to leverage those types by default in that release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem binding DateOnly in ASP.NET Core 6 MVC
Full binding support for DateOnly and TimeOnly isn't available yet. Another related issue is this one. This is planned for .NET 7.
Read more >
DateOnly serialization not working properly as of 2.19.0
Summary. We have a component that listens to events and saves all properties of the event to a mongo database. We set it...
Read more >
Date, Time, and Time Zone Enhancements in .NET 6
In this blog post, I'm going to cover the following topics: The new DateOnly and TimeOnly types; Time Zone Conversion APIs; Time Zone...
Read more >
Dont' Do That, Do This: The .NET 6 Edition : r/csharp
The one big reason is adding dates, if you add time to a date + time, you have to somehow account for the...
Read more >
Using DateOnly and TimeOnly in .NET 6 - Steve Gordon
DateOnly and TimeOnly allow developers to represent either the date or time portion of a DateTime. These two new types are structs (value...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found