Skip to content

Update ConnectorConverter to honer JsonIgnore and JsonPropertyName #305

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

Merged

Conversation

msftshlomiyosef
Copy link
Contributor

@msftshlomiyosef msftshlomiyosef commented May 22, 2025

Fixes #298
Added GetCachedProperties: Caches PropertyInfo[] per type to avoid repeated reflection.
Added GetPropertyMap: Resolves JSON property names considering:

  • JsonPropertyName attributes
  • JsonNamingPolicy
  • Case insensitivity (optional)
  • Results are cached for efficiency

Added support for JsonIgnoreAttribute during serialization to skip ignored properties
Use JsonPropertyNameAttribute to ensure property names are correctly mapped during read/write
Remove manual property name handling in AIEntityConverter

@msftshlomiyosef msftshlomiyosef force-pushed the users/shlomiyosef/converter-use-porp-name-and-ignore branch from ee16fee to 4eb259a Compare May 27, 2025 13:31
@msftshlomiyosef msftshlomiyosef marked this pull request as ready for review May 27, 2025 13:33
@Copilot Copilot AI review requested due to automatic review settings May 27, 2025 13:33
@msftshlomiyosef msftshlomiyosef requested a review from a team as a code owner May 27, 2025 13:33
Copy link
Contributor

@Copilot 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 updates the ConnectorConverter to respect [JsonIgnore] and [JsonPropertyName] attributes, adds reflection-based caching to improve performance, and removes manual property handling in the AIEntityConverter. Corresponding tests have been added to verify derived-entity support, concurrency safety, and duplicate property-name errors.

  • Introduce GetCachedProperties and GetPropertyMap with caching in ConnectorConverter
  • Honor JsonIgnoreAttribute and JsonPropertyNameAttribute when writing JSON
  • Remove handwritten type/context/id mapping in AIEntityConverter and enable attribute-based mapping
  • Add tests for derived entities, list serialization, concurrency, and duplicate JSON property detection

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/tests/Microsoft.Agents.Model.Tests/ObjectSerializationTests.cs Added tests for derived-entity serialization, list-of-activities, concurrency, and duplicate-name errors
src/libraries/Core/Microsoft.Agents.Core/Serialization/Converters/ConnectorConverter.cs Added property-reflection caching, name-resolution cache, and attribute handling
src/libraries/Core/Microsoft.Agents.Core/Serialization/Converters/AIEntityConverter.cs Removed manual @type/@context/@id branches in favor of attribute-based mapping
src/libraries/Core/Microsoft.Agents.Core/Models/AIEntity.cs Uncommented [JsonPropertyName] on AtType, AtContext, and AtId
Comments suppressed due to low confidence (1)

src/tests/Microsoft.Agents.Model.Tests/ObjectSerializationTests.cs:382

  • [nitpick] The [ ... ] collection expression may not be recognized in all C# versions or contexts. For clarity and compatibility, consider using new List<Activity> { new DerivedActivity { ... } }.
List<Activity> activities = [new DerivedActivity

@tracyboehrer tracyboehrer requested a review from MattB-msft May 28, 2025 02:44
@msftshlomiyosef msftshlomiyosef merged commit d95f98d into main May 28, 2025
8 checks passed
@msftshlomiyosef msftshlomiyosef deleted the users/shlomiyosef/converter-use-porp-name-and-ignore branch May 28, 2025 03:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ML: Core Tags changes to core libraries ML: Tests Tags changes to tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AIEntityConverter Not Invoked When Serializing AIEntity Inside Activity.Entities
2 participants