Update Numeric Types: Add int64 and string support for AttributeTypeInt64#93
Update Numeric Types: Add int64 and string support for AttributeTypeInt64#93Saurabhdarekar merged 1 commit intomainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #93 +/- ##
==========================================
+ Coverage 48.68% 50.16% +1.48%
==========================================
Files 24 24
Lines 2654 2675 +21
==========================================
+ Hits 1292 1342 +50
+ Misses 1306 1287 -19
+ Partials 56 46 -10 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
This PR enhances numeric type handling in the JSON value conversion framework by adding comprehensive support for int64 and string inputs for AttributeTypeInt64 and AttributeTypeDouble. The changes improve developer experience by allowing direct int64 values and string parsing while adding precision validation to prevent data corruption.
Key Changes
- Extended AttributeTypeInt64 to handle int64, float64 (with validation), and string inputs
- Enhanced AttributeTypeDouble to support string parsing in addition to float64
- Added comprehensive test coverage for all new input type combinations and edge cases
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| web/json_value.go | Core conversion logic updates for AttributeTypeInt64 and AttributeTypeDouble with new type support and validation |
| web/json_value_test.go | Unit tests for individual attribute conversion scenarios including edge cases and error conditions |
| web/json_object_test.go | Integration tests for JSON object processing with comprehensive coverage of mixed types and error handling |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
This PR is a copy of original #90. I have migrated to a new PR as for old PR codeQL workflow was not working.
The framework.AttributeTypeInt64 handler in web/json_value.go only accepted float64 values, causing failures when developers provided int64 or string values directly. This forced adapter developers to manually cast values to float64 before passing them to the framework - a poor developer experience that also introduced precision loss for large integers.
Example of the issue:
// This would fail with the old implementation
obj.WithAttribute("userId", int64(123456789012345)) // Error!
// Developers had to do this workaround:
obj.WithAttribute("userId", float64(myInt64Value)) // Ugly + precision loss
Solution
Enhanced the AttributeTypeInt64 case to handle three input types:
Key Improvements
🛡️ Precision Safety: Added validation for float64 → int64 conversions
🚀 Expanded Range: String parsing supports the full int64 range without precision loss
✨ Better Developer Experience:
Testing
Breaking Changes