Add JsonConstructor attributes to Date and Time for System.Text.Json deserialization#641
Open
Add JsonConstructor attributes to Date and Time for System.Text.Json deserialization#641
Conversation
…ation Co-authored-by: gavinbarron <7122716+gavinbarron@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix deserialization issue for Date and Time types in JSON
Add JsonConstructor attributes to Date and Time for System.Text.Json deserialization
Feb 4, 2026
Contributor
|
@copilot please run dotnet format |
Co-authored-by: gavinbarron <7122716+gavinbarron@users.noreply.github.com>
Contributor
Author
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fix Date and Time deserialization with System.Text.Json ✅
Plan:
[JsonConstructor]attribute toDate(int year, int month, int day)constructor[JsonConstructor]attribute toTime(int hour, int minute, int second)constructorDateTests.cswith System.Text.Json deserialization testsTimeTests.csSummary
Successfully fixed the deserialization issue with
DateandTimetypes when usingSystem.Text.Json.JsonSerializer.Changes Made:
Microsoft.Kiota.Abstractions.csproj: Added System.Text.Json package reference (version 6.0.10+) for netstandard2.0, netstandard2.1, and net5.0 targetsDate.cs: Addedusing System.Text.Json.Serialization;and[JsonConstructor]attribute to theDate(int year, int month, int day)constructorTime.cs: Addedusing System.Text.Json.Serialization;and[JsonConstructor]attribute to theTime(int hour, int minute, int second)constructorDateTests.cs: Added 4 comprehensive tests for Date serialization, deserialization, round-trip, and ToStringTimeTests.cs: Added 3 new tests for Time serialization, deserialization, and round-tripdotnet formatto fix whitespace formatting in DateTests.csTest Results:
Security Summary:
No security vulnerabilities were discovered or introduced by this change.
Original prompt
System.Text.Json.JsonSerializercannot deserializeDateandTimetypes using default converters #580✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.