Fix numeric strings being parsed as integers in JSON request bodies#421
Fix numeric strings being parsed as integers in JSON request bodies#421dargmuesli merged 3 commits intomasterfrom
Conversation
Co-authored-by: dargmuesli <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #421 +/- ##
============================================
- Coverage 66.37% 66.34% -0.04%
- Complexity 674 675 +1
============================================
Files 184 184
Lines 7120 7128 +8
Branches 1145 1148 +3
============================================
+ Hits 4726 4729 +3
- Misses 1491 1496 +5
Partials 903 903 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@copilot ensure that other numeric body parameters like |
…ing parameters as strings Co-authored-by: dargmuesli <[email protected]>
Fixed! Numeric parameters like |
Problem
String parameters containing numeric values were incorrectly converted to JSON numbers instead of remaining as strings when creating API requests. This caused playlist creation to fail when using numeric strings for names or descriptions.
Example issue:
Before (broken):
{"name":2025,"description":2025}❌After (fixed):
{"name":"2025","description":"2025"}✅Root Cause
In
AbstractRequest.bodyParametersToJson(), the code attempted to parse all parameter values as JSON usingJsonParser.parseString(). This converted:"2025"→2025(number)"123.45"→123.45(number)"true"→true(boolean)"null"→null(JSON null)Solution
Modified
bodyParametersToJson()to always treat parameter values as strings usingjsonObject.addProperty(name, value)instead of attempting JSON parsing. This preserves the caller's intent when they explicitly pass string values.Key changes:
JsonParser.parseString()attempt for parameter valuesaddProperty()to ensure values remain as string primitivesTesting
This change ensures string parameters always serialize as JSON strings, preventing API validation failures while maintaining backward compatibility.
Fixes #420.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.