SAP OData v2 services expect Edm.Decimal fields to be sent as JSON strings, not JSON numbers. Sending numeric values as JSON numbers results in errors like:
Failed to read property 'Quantity' at offset '71'
The Go implementation now automatically converts numeric values to strings for fields that are likely to be Edm.Decimal types in SAP.
The implementation uses heuristic-based field name matching to identify decimal fields. Fields containing these patterns are automatically converted:
quantity,qtyamount,amtprice,costvalue,valtotal,sumnet,grosstax,vatdiscount,rate,percentageweight,volume,size- And many more...
When creating or updating entities:
Input (from user):
{
"Quantity": 1,
"Price": 99.99,
"Description": "Laptop"
}Output (sent to SAP):
{
"Quantity": "1",
"Price": "99.99",
"Description": "Laptop"
}All numeric types are converted to strings:
int,int8,int16,int32,int64uint,uint8,uint16,uint32,uint64float32,float64
Non-numeric types (strings, bools, nil) are left unchanged.
The conversion works recursively through:
- Nested objects
- Arrays of objects
- Complex hierarchical structures
Before (would fail):
{
"SalesOrderID": "0500010047",
"ProductID": "HT-1251",
"Quantity": 1,
"QuantityUnit": "EA",
"DeliveryDate": "2025-06-24T00:00:00"
}After conversion (works):
{
"SalesOrderID": "0500010047",
"ProductID": "HT-1251",
"Quantity": "1",
"QuantityUnit": "EA",
"DeliveryDate": "/Date(1750377600000)/"
}Note: Date conversion also happens if legacy dates are enabled (default for SAP).
Run the included tests:
# Unit tests
go test ./internal/test/numeric_conversion_test.go -v
# Demo
go run test_numeric_conversion.go
go run test_json_output.goThe Python implementation likely performs similar conversions. Both implementations now:
- Detect decimal fields by name patterns
- Convert numeric values to strings
- Handle nested structures
- Maintain compatibility with SAP OData v2
- The heuristic approach may miss some decimal fields with unusual names
- Fields explicitly marked as
Edm.Int32or other non-decimal types are still converted if their names match patterns - No metadata-based type detection (would require parsing OData metadata)
- Parse OData metadata to get exact field types
- Allow configuration to override field detection
- Add support for custom field patterns
- Provide option to disable automatic conversion