Title:
Using DeserializeJSON ColdFusion deserializes numeric values and rounds decimal value
| View in TrackerStatus/Resolution/Reason: Closed/Withdrawn/HighRisk
Reporter/Name(from Bugbase): Jeff Howden / Jeff Howden ()
Created: 03/04/2018
Components: Language, Serialization
Versions: 11.0
Failure Type: Data Corruption
Found In Build/Fixed In Build: Standard Edition, version 11,0,13,303668 /
Priority/Frequency: Normal / All users will encounter
Locale/System: English / Win 2012 Server x64
Vote Count: 0
Problem Description:
Using DeserializeJSON ColdFusion deserializes string to numeric and truncates value
Steps to Reproduce:
<cfscript>
token = StructNew();
token['ts'] = ArrayNew(1);
token['ts'][1] = 1520205024.000075;
token['ts'][2] = 1520205024.00075;
token['ts'][3] = 1520205024.0075;
token['ts'][4] = 1520205024.075;
token['ts'][5] = 1520205024.75;
</cfscript>
<cfdump var="#token#">
<cfdump var="#SerializeJSON(token)#">
<cfdump var="#DeserializeJSON(SerializeJSON(token))#">
Actual Result:
struct ts
array
1 1520205024.000075
2 1520205024.00075
3 1520205024.0075
4 1520205024.075
5 1520205024.75
{"ts":[1520205024.000075,1520205024.00075,1520205024.0075,1520205024.075,1520205024.75]}
struct ts
array
1 1520205024
2 1520205024
3 1520205024.01
4 1520205024.08
5 1520205024.75
Expected Result:
struct ts
array
1 1520205024.000075
2 1520205024.00075
3 1520205024.0075
4 1520205024.075
5 1520205024.75
{"ts":[1520205024.000075,1520205024.00075,1520205024.0075,1520205024.075,1520205024.75]}
struct ts
array
1 1520205024.000075
2 1520205024.00075
3 1520205024.0075
4 1520205024.075
5 1520205024.75
Any Workarounds:
It's not enough to simply quote the values in the in-memory struct prior to serialization with SerializeJSON as the string data type of the values will be lost. There's only a partial workaround and that's to serialize the data in some other say such that the numeric values are treated as strings. Only then does DeserializeJSON respect the values.
{"ts":["1520205024.000075","1520205024.00075","1520205024.0075","1520205024.075","1520205024.75"]}
struct ts
array
1 1520205024.000075
2 1520205024.00075
3 1520205024.0075
4 1520205024.075
5 1520205024.75
Attachments:
- March 04, 2018 00:00:00: CF-4201396.cfm
Comments: