-
Notifications
You must be signed in to change notification settings - Fork 5k
[API Proposal]: Utf8JsonReader DateTimeOffset TimeZone Overloads #105583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Utf8JsonReader includes the |
I see. I was hoping to avoid needing to copy and duplicate all of the logic inside the A much broader scoped alternative for the need to copy/paste a lot of internal runtime code for relatively small changes would be to do something akin to what dotnet/efcore does - begin exposing parts of the internal runtime surface area with the The latter option would likely serve both objectives - it would keep the official public API surface area smaller while allowing developers with advanced use cases to judiciously identify some areas where they can keep their own total lines of code to maintain down with some selective re-use. |
Closing based on Eirik's response above. |
I'm not sure I follow, what APIs would you like to see exposed that aren't available today?
Even though |
I was commenting on the amount of lines of i.e.
It would simply be a nice to have, if we we're able to find a better balance between the important objective of keeping the runtime/BCL public api surface area small while also allowing developers with more advanced use cases ways to leverage some of that internal code in lieu of duplicating and increasing their own # of lines of code to maintain. |
The built-in date parser in STJ is mostly a polyfill of the implementation available in the |
Background and motivation
The System.Text.Json base class library has support for efficient reading of DateTime and DateTimeOffset types.
However these implementations currently all fallback to assuming the DateTime/DateTimeOffset should be constructed as DateTimeKind.Local if the json token does not include the "Z" suffix or an explicit timezone offset. See JsonHelpers.TryParseAsISO
It would be advantageous for developers if these methods, such as Utf8Reader.TryGetDateTimeOffset were overloaded such that the developer can supply an explicit time zone offset to fallback on if the json token does not include the time zone.
One example usage would be a custom JsonConverter that wishes to use Utf8Reader.TryGetDateTimeOffset for efficiency as described in the microsoft docs here. Currently, if the developer needed such a converter to use an explicit offset as the fallback, they would be forced to use a less efficient option of reading the token as a string and then parsing it explicitly after the fact.
API Proposal
Similar methods in the System.Text.Json namespace such as JsonElement.(Try)GetDateTimeOffset would also benefit from such an overload.
API Usage
Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: