tracker issue : CF-3695627

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

SerializeJSON turns strings that look like scientific notation into floats.

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/

Reporter/Name(from Bugbase): Chris Phillips / Chris Phillips (cf_chris)

Created: 01/17/2014

Components: AJAX, Plumbing

Versions: 10.0

Failure Type: Data Corruption

Found In Build/Fixed In Build: Final, 287843 / CF10_Update14

Priority/Frequency: Critical / Some users will encounter

Locale/System: English / Windows 7 64-bit

Vote Count: 1

Problem Description:
SerializeJSON turns strings that look like scientific notation into floats. 
In our case those strings happen to be Stock Numbers. Changing them to floats is breaking our application.
Furthermore, I would be surprised if anyone that is using CF would find this a desired behavior. If someone WERE passing around a "string" that WAS in scientific notation, I DO NOT think the would want it CHANGED when serialized to JSON.

Steps to Reproduce:
<cfoutput>
	<cfset str = "1234E-1" />
	<p>#SerializeJSON({str: str})#</p><!--- No space --->
	<p>#SerializeJSON({str: str & " "})#</p><!--- Space at the end --->
	<p>#SerializeJSON({str: " " & str})#</p><!--- Space at the beginning--->
</cfoutput>

Actual Result:
{"STR":123.4}    // WRONG
{"STR":123.4}    // WRONG
{"STR":" 1234E-1"} // CORRECT (But, I don't want spaces BEFORE my string.)

Expected Result:
{"STR":"1234E-1"}  // No space
{"STR":"1234E-1 "}  // Space at the end
{"STR":" 7373E-1"}  // Space at the beginning

Any Workarounds:
Only ones that are too awful to mention.

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3695627

External Customer Info:
External Company:  
External Customer Name: cf_chris
External Customer Email:  
External Test Config: My Hardware and Environment details:

Windows 7 (SP1) 64-bit

ColdFusion 10 - 10,0,12,286680

Java Version - 1.7.0_17

Attachments:

Comments:

At the time of serialization , datatype information of an object is not available (cause CF is typeless) and hence knowing the original datatype and convert it according is not possible sometimes and this is one of those cases.
Comment by Awdhesh K.
13657 | January 21, 2014 05:58:01 AM GMT
I have to say I'm disappointed in this response. There are a number of other SerializeJSON issues that seem related to proper/improper conversion of string values that have been fixed. I don't see why this one should be different. SerializeJSON needs to be a rock-solid, dependable function for all users, as JSON data is so heavily used in modern web applications. If users can't depend on this function to properly serialize data, most will turn to 3rd party UDF alternatives that do work properly.
Comment by External U.
13658 | January 21, 2014 11:25:35 AM GMT
By the way, this has bitten me as well, with strings like "49E4" (notice the absence of the hyphen in this case).
Comment by External U.
13659 | January 21, 2014 11:26:26 AM GMT
This issue forced me to turn to a UDF to serialize my JSON data. Please consider reopening this bug.
Vote by External U.
13669 | January 21, 2014 11:27:18 AM GMT
So if you can't do it properly (and, seriously, you have to get your act together, and *find a way*. Railo can do this just fine), then *don't try*. It's a string. LEAVE IT AS A STRING. That's the problem. If you didn't *try* to mess around with it's data type, then you'd not have this problem. Fundamental stuff like this *has to work*. You can't just say "it's a bit hard, sorry". -- Adam
Comment by External U.
13660 | January 21, 2014 11:31:39 AM GMT
This is a rubbish answer. I'm tired of rubbish answers. How about you get your act together and fix some existing bugs before adding an even larger batch in CF11.
Comment by External U.
13661 | January 21, 2014 11:39:33 AM GMT
Would either of you (Adam and Carl) like to suggest an alternative UDF or CFC for me to use while Adobe continues to let ACF slide into irrelevance?
Comment by External U.
13662 | January 21, 2014 11:40:40 AM GMT
I think a solution here might be fore CF to cater for type mapping. Exactly how to do that, I don't know. But it needs to be made to work *somehow*. In the interim, Ben Nadel has written this: http://www.bennadel.com/blog/2505-JsonSerializer-cfc-A-Data-Serialization-Utility-For-ColdFusion.htm. I don't like his chained method approach (it seems done purely for the sake of doing it that way, rather than it being a good approach), but it should work. -- Adam
Comment by External U.
13663 | January 21, 2014 11:45:56 AM GMT
@cf_chris - I've been using JSONUtil.cfc by Nathan Mische. http://jsonutil.riaforge.org/
Comment by External U.
13664 | January 21, 2014 11:53:40 AM GMT
I'll have to check out JSONUtil.cfc. FYI. This works fine in Railo. (So, apparently it's possible.)
Comment by External U.
13665 | January 21, 2014 12:05:43 PM GMT
Fix tested on build, 288817.
Comment by Immanuel N.
13666 | March 05, 2014 07:16:37 AM GMT
This is listed as being fixed in 10,0,14,291717 (see http://helpx.adobe.com/coldfusion/kb/bugs-fixed-coldfusion-10-update.html), but it's not. The results of Chris's test code is: {"STR":1234E-1} {"STR":1234E-1 } {"STR":" 1234E-1"} Only the last come is correct. -- Adam
Comment by External U.
13667 | October 14, 2014 03:13:05 PM GMT
Also, another example of breaking: writeOutput( serializeJSON( { "product_id" : "1034E2343"} ) );
Comment by External U.
13668 | October 15, 2014 07:49:49 AM GMT