Skip to content

fix: JsonSerializer - "True" string conversion to "Bool" type#15

Merged
IvanMurzak merged 14 commits into
mainfrom
fix/json-serializer
Sep 26, 2025
Merged

fix: JsonSerializer - "True" string conversion to "Bool" type#15
IvanMurzak merged 14 commits into
mainfrom
fix/json-serializer

Conversation

@IvanMurzak

Copy link
Copy Markdown
Owner

This pull request introduces improvements to the parameter conversion logic in the MethodWrapper class, enhancing how primitive types are handled when passed as string values in JSON. These changes make method invocation via JSON arguments more robust and flexible, especially for scenarios where primitive parameters might be encoded as strings. Additionally, the project version is incremented to reflect these updates.

Parameter conversion enhancements:

  • Added a new helper method TryConvertStringToPrimitive in MethodWrapper.cs to robustly parse string values to their corresponding primitive types, including support for nullable types, enums, and common .NET primitives. This ensures that string-encoded primitives in JSON are correctly converted during method invocation.
  • Updated the parameter conversion logic in VerifyParameters to first attempt conversion of string values to primitives using the new helper method before falling back to standard deserialization. This improves compatibility with various JSON representations of primitive arguments. [1] [2]

Other changes:

  • Incremented the library version in ReflectorNet.csproj from 1.1.0 to 1.1.1 to reflect the new functionality and bug fixes.

@IvanMurzak IvanMurzak requested a review from Copilot September 22, 2025 09:48
@IvanMurzak IvanMurzak self-assigned this Sep 22, 2025
@IvanMurzak IvanMurzak added the bug Something isn't working label Sep 22, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 improves the parameter conversion logic in the MethodWrapper class to better handle primitive types passed as string values in JSON, making method invocation more robust when dealing with string-encoded primitives.

  • Added a new TryConvertStringToPrimitive helper method to parse string values to their corresponding primitive types
  • Enhanced parameter conversion logic to attempt string-to-primitive conversion before falling back to standard deserialization
  • Incremented library version from 1.1.0 to 1.1.1

Reviewed Changes

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

File Description
ReflectorNet/src/Reflector/MethodWrapper.cs Added primitive type conversion helper and integrated it into parameter verification logic
ReflectorNet/ReflectorNet.csproj Version bump to reflect new functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread ReflectorNet/src/Reflector/MethodWrapper.cs Outdated
Comment thread ReflectorNet/src/Reflector/MethodWrapper.cs Outdated
Comment thread ReflectorNet/src/Reflector/MethodWrapper.cs Outdated
- Implemented StringToPrimitiveConverter to handle deserialization of JSON string values to various primitive types including bool, int, long, float, double, decimal, DateTime, DateTimeOffset, TimeSpan, Guid, and enums.
- Added comprehensive unit tests for StringToPrimitiveConverter covering valid and invalid cases for each supported type.
- Updated MethodWrapper to improve error messages for parameter type mismatches.
- Enhanced error handling in GetParameterValue to provide clearer exceptions when conversion fails.
- Integrated StringToPrimitiveConverter into the JsonSerializer options.
- Modified existing ErrorHandlingTests to ensure case-insensitive checks for exception messages.
… DateTimeOffset, Decimal, Enum, Guid, Primitive, and TimeSpan
…ing converters

- Introduced new JSON converters for various primitive types: Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64, Single, and Double.
- Enhanced EnumJsonConverter to use Enum.TryParse for better error handling.
- Removed the monolithic PrimitiveJsonConverter in favor of individual converters for improved maintainability and clarity.
- Updated TimeSpanJsonConverter to write TimeSpan as ticks instead of ISO 8601 string.
- Improved error messages in MethodWrapper for better debugging information.
- Re-enabled individual primitive type converters in JsonSerializer.
@IvanMurzak IvanMurzak requested a review from Copilot September 26, 2025 03:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 25 out of 25 changed files in this pull request and generated 7 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread ReflectorNet/src/Convertor/Json/GuidJsonConverter.cs Outdated
Comment thread ReflectorNet/src/Convertor/Json/DateTimeJsonConverter.cs Outdated
Comment thread ReflectorNet/src/Convertor/Json/DateTimeOffsetJsonConverter.cs Outdated
Comment thread ReflectorNet/src/Convertor/Json/BoolJsonConverter.cs Outdated
Comment thread ReflectorNet/src/Convertor/Json/BoolJsonConverter.cs Outdated
Comment thread ReflectorNet/src/Convertor/Json/EnumJsonConverter.cs Outdated
Comment thread ReflectorNet/src/Reflector/MethodWrapper.cs Outdated
- Updated error messages in various JSON converters to use GetTypeName(pretty: true) for better readability.
- Enhanced exception handling in MethodWrapper to provide clearer type mismatch information.
- Ensured consistent error reporting across all converters for null and type conversion issues.
@IvanMurzak IvanMurzak requested a review from Copilot September 26, 2025 04:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 30 out of 30 changed files in this pull request and generated 5 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread ReflectorNet/src/Convertor/Json/BoolJsonConverter.cs
Comment thread ReflectorNet/src/Convertor/Json/BoolJsonConverter.cs
Comment thread ReflectorNet/src/Convertor/Json/GuidJsonConverter.cs Outdated
Comment thread ReflectorNet/src/Reflector/MethodWrapper.cs Outdated
Comment thread ReflectorNet/ReflectorNet.csproj
@IvanMurzak IvanMurzak requested a review from Copilot September 26, 2025 04:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 30 out of 30 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@IvanMurzak IvanMurzak merged commit 70b195a into main Sep 26, 2025
1 check passed
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.

2 participants