tracker issue : CF-4201396

select a category, or use search below
(searches all categories and all time range)
Title:

Using DeserializeJSON ColdFusion deserializes numeric values and rounds decimal value

| View in Tracker

Status/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:

  1. March 04, 2018 00:00:00: CF-4201396.cfm

Comments:

Changing this causes backward compatibility issues. Whenever we are converting double values (e.g 1520205024.000075) to string we are losing the fraction part and is getting rounded off (result 1520205024). When the double value is greater than -10,000 and less than 1000000000000 we are displaying the whole number but displaying only 12 most significant digits. If you take the number 1520205024.000075 for example which is greater than -10,000 and less than 1000000000000 when converted to string its value just keeping 12 significant digits is 1520205024.00 which was rounded off and results 1520205024.
Comment by S V.
27527 | April 16, 2018 08:41:26 AM GMT
Potential to introduce backward compatibility issues in databases where column size is expected as 12 digit only. More as Pavan explained.
Comment by Awdhesh K.
27528 | April 18, 2018 07:43:41 AM GMT