Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 2, 2025

The Arguments property on InvocationDescription was not being deserialized correctly when using either System.Text.Json or Newtonsoft.Json. This occurred because the class only had a primary constructor for basic parameters but lacked a JsonConstructor to handle the Arguments collection during deserialization.

Problem

Given JSON like this:

{
  "$type": "DendroDocs.InvocationDescription, DendroDocs.Shared",
  "ContainingType": "Pitstop.Infrastructure.Messaging.IMessagePublisher",
  "Name": "PublishMessageAsync",
  "Arguments": [
    {
      "Type": "string",
      "Text": "e.MessageType"
    },
    {
      "Type": "Pitstop.CustomerManagementAPI.Events.CustomerRegistered", 
      "Text": "e"
    }
  ]
}

The Arguments collection would remain empty after deserialization, resulting in loss of important method call information.

Solution

Added a JsonConstructor to InvocationDescription following the established pattern used by ConstructorDescription and MethodDescription:

  • Added optional arguments parameter to the constructor that populates the Arguments collection
  • Added ConcreteTypeConverter attribute for Newtonsoft.Json compatibility
  • Added proper using statement for JSON utilities

Changes Made

  • InvocationDescription.cs: Added JsonConstructor and Newtonsoft.Json attributes
  • Test Coverage: Added comprehensive regression tests for both serializers including the original issue scenario

The fix is minimal, follows existing codebase patterns, and maintains full backward compatibility while enabling proper deserialization of method invocations with arguments.

Fixes #50.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

…ation

Co-authored-by: eNeRGy164 <10671831+eNeRGy164@users.noreply.github.com>
Copilot AI changed the title [WIP] Arguments of an Invocation are not deserialized. Fix InvocationDescription Arguments deserialization for both JSON serializers Jul 2, 2025
Copilot AI requested a review from eNeRGy164 July 2, 2025 12:51
Copilot finished work on behalf of eNeRGy164 July 2, 2025 12:51
@eNeRGy164 eNeRGy164 marked this pull request as ready for review July 2, 2025 12:53
Copilot AI review requested due to automatic review settings July 2, 2025 12:53
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 the deserialization of the Arguments property on InvocationDescription for both System.Text.Json and Newtonsoft.Json by introducing a dedicated constructor and converter attributes, and adds regression tests to verify behavior.

  • Added a JsonConstructor overload on InvocationDescription that accepts an argument list and populates the Arguments collection.
  • Applied Newtonsoft converter attributes to the Arguments property for proper type handling.
  • Introduced comprehensive TextJson and Newtonsoft.Json tests to cover simple and complex invocation scenarios.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/DendroDocs.Shared/Descriptions/InvocationDescription.cs Added a JsonConstructor overload, converter attributes, and import
tests/.../TextJsonDeserializationTests.cs Added TextJson tests for invocation argument deserialization
tests/.../NewtonsoftDeserializationTests.cs Added Newtonsoft.Json tests for invocation argument deserialization
Comments suppressed due to low confidence (1)

src/DendroDocs.Shared/Descriptions/InvocationDescription.cs:40

  • The [] initializer is valid only for arrays. For List<ArgumentDescription>, use = new() or an explicit collection initializer to avoid a compilation error.
    public List<ArgumentDescription> Arguments { get; } = [];

@coveralls
Copy link

Pull Request Test Coverage Report for Build 16025606938

Details

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.03%) to 96.275%

Totals Coverage Status
Change from base Build 16019923727: 0.03%
Covered Lines: 573
Relevant Lines: 578

💛 - Coveralls

@coveralls
Copy link

Pull Request Test Coverage Report for Build 16025607078

Details

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.03%) to 96.275%

Totals Coverage Status
Change from base Build 16019923727: 0.03%
Covered Lines: 573
Relevant Lines: 578

💛 - Coveralls

@eNeRGy164 eNeRGy164 merged commit 173adba into main Jul 2, 2025
4 checks passed
@eNeRGy164 eNeRGy164 deleted the copilot/fix-50 branch July 2, 2025 12:56
@eNeRGy164 eNeRGy164 added the bug Something isn't working label Jul 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Arguments of an Invocation are not deserialized.

3 participants