Skip to content

Conversation

@stephentoub
Copy link
Member

@stephentoub stephentoub commented Oct 25, 2025

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

Serialization of variables typed as UserInputRequestContent / UserInputResponseContent would fail, because JsonSerializer doesn't recognize them as part of a hierarchy.
@stephentoub stephentoub requested a review from a team as a code owner October 25, 2025 02:24
Copilot AI review requested due to automatic review settings October 25, 2025 02:24
@stephentoub
Copy link
Member Author

cc: @crickman

@github-actions github-actions bot added the area-ai Microsoft.Extensions.AI libraries label Oct 25, 2025
Copy link
Contributor

Copilot AI left a 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 JsonPolymorphic and JsonDerivedType attributes 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

…ents/UserInputResponseContentTests.cs

Co-authored-by: Copilot <[email protected]>
@stephentoub stephentoub enabled auto-merge (squash) October 27, 2025 15:14
@stephentoub stephentoub merged commit d02b73e into dotnet:main Oct 27, 2025
6 checks passed
jeffhandley pushed a commit to jeffhandley/extensions that referenced this pull request Nov 1, 2025
* 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]>
jeffhandley pushed a commit that referenced this pull request Nov 2, 2025
* 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]>
This was referenced Nov 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-ai Microsoft.Extensions.AI libraries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants