-
Notifications
You must be signed in to change notification settings - Fork 844
Fix serialization of UserInputRequest/ResponseContent #6962
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
Conversation
Serialization of variables typed as UserInputRequestContent / UserInputResponseContent would fail, because JsonSerializer doesn't recognize them as part of a hierarchy.
|
cc: @crickman |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a JSON serialization issue for UserInputRequestContent and UserInputResponseContent types by adding proper polymorphic serialization support. The fix ensures that derived types in these hierarchies can be correctly serialized and deserialized through JsonSerializer.
Key changes:
- Added
JsonPolymorphicandJsonDerivedTypeattributes to base content classes - Registered base types in the default JSON serializer context
- Added comprehensive serialization roundtrip tests for all affected content types
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
UserInputRequestContent.cs |
Added polymorphic JSON serialization attributes for derived type support |
UserInputResponseContent.cs |
Added polymorphic JSON serialization attributes for derived type support |
AIJsonUtilities.Defaults.cs |
Registered base content types in default JSON context |
TestJsonSerializerContext.cs |
Added array type registrations for test serialization |
UserInputRequestContentTests.cs |
Added test validating serialization of request content and derived types |
UserInputResponseContentTests.cs |
Added test validating serialization of response content and derived types |
FunctionApprovalRequestContentTests.cs |
Added serialization roundtrip test |
FunctionApprovalResponseContentTests.cs |
Added serialization roundtrip test |
HostedFileContentTests.cs |
Added serialization roundtrip test |
HostedVectorStoreContentTests.cs |
Added serialization roundtrip test |
McpServerToolResultContentTests.cs |
Added serialization roundtrip test |
TextContentTests.cs |
Added serialization roundtrip test |
TextReasoningContentTests.cs |
Added serialization roundtrip test |
UsageContentTests.cs |
Added serialization roundtrip test |
...ibraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/UserInputRequestContentTests.cs
Show resolved
Hide resolved
...braries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/UserInputResponseContentTests.cs
Outdated
Show resolved
Hide resolved
…ents/UserInputResponseContentTests.cs Co-authored-by: Copilot <[email protected]>
...braries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/UserInputResponseContentTests.cs
Outdated
Show resolved
Hide resolved
…ents/UserInputResponseContentTests.cs
* Fix serialization of UserInputRequest/ResponseContent Serialization of variables typed as UserInputRequestContent / UserInputResponseContent would fail, because JsonSerializer doesn't recognize them as part of a hierarchy. * Update test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/UserInputResponseContentTests.cs Co-authored-by: Copilot <[email protected]> * Update test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/UserInputResponseContentTests.cs --------- Co-authored-by: Copilot <[email protected]>
* Fix serialization of UserInputRequest/ResponseContent Serialization of variables typed as UserInputRequestContent / UserInputResponseContent would fail, because JsonSerializer doesn't recognize them as part of a hierarchy. * Update test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/UserInputResponseContentTests.cs Co-authored-by: Copilot <[email protected]> * Update test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/UserInputResponseContentTests.cs --------- Co-authored-by: Copilot <[email protected]>
Serialization of variables typed as UserInputRequestContent / UserInputResponseContent would fail, because JsonSerializer doesn't recognize them as part of a hierarchy.
Microsoft Reviewers: Open in CodeFlow