fix: JsonSerializer - "True" string conversion to "Bool" type#15
Conversation
There was a problem hiding this comment.
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
TryConvertStringToPrimitivehelper 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.
- 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.
There was a problem hiding this comment.
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.
- 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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
This pull request introduces improvements to the parameter conversion logic in the
MethodWrapperclass, 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:
TryConvertStringToPrimitiveinMethodWrapper.csto 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.VerifyParametersto 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:
ReflectorNet.csprojfrom1.1.0to1.1.1to reflect the new functionality and bug fixes.