tracker issue : CF-3667877

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

Deserializing a a json string where some variables have values of null changes those values

| View in Tracker

Status/Resolution/Reason: Closed/Withdrawn/NotABug

Reporter/Name(from Bugbase): Donald Langhorne / Donald Langhorne (Donald Langhorne)

Created: 11/14/2013

Components: Language, Serialization

Versions: 10.0

Failure Type: Data Corruption

Found In Build/Fixed In Build: Final /

Priority/Frequency: Critical / All users will encounter

Locale/System: English / Platforms All

Vote Count: 1

Problem Description:
I discovered this when I tried to use a json string where some values were null.  When I used deserializeJson() it changes null to: [undefined array element] Element 1 is undefined in a Java object of type class coldfusion.runtime.Array.

What is most troublesome is that as I show in my example, when I run my query through serializeJson, THAT function sets the null field values to null (no quotes).  This is also FYI identical to how the php json_encode() function works.  I consider this to be correct.

If I then take that CF created json string and run it through deSerializeJson() it cannot handle the value null and the result is a string that displays an error.

Steps to Reproduce:
<!--- Simply modify query so that it returns records from a table that has fields that allow NULL AND some of the fields are set to NULL.  I limited to top 10 only to reduce my recordset which is much much larger --->

<cfquery name="get" datasource="#Application.Datasource#">
	select top 10 * from pages
</cfquery>

<cfset js = serializeJson(get,true) />
<cfdump var="#js#" />
<Cfset jsObj = deserializeJson(js) />
<cfdump var="#jsObj#">
Actual Result:

any json variables that have a value = null that are passed through deserializeJson() result in the value being changed to a CF error string

Further, I initially discovered this by taking a json string, running it through deSerializeJson() then using the resulting array variable in a for-in loop.  When I did this:

for (item in pagesData) {
	writeDump(item);
}

The values were set as 'undefined', so yet ANOTHER conversion to a different value.

Expected Result:
The value should remain as null, even if it is simply a string NULL, or even an empty string would be better than what it is currently doing.  

Any Workarounds:

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

Watson Bug ID:	3667877

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



I have tested this both on a Macbook Pro running CF 10 as well as an ubuntu 12.04 system also running CF 10.  Mac is obviously 64-bit, the ubuntu system was 32-bit

Attachments:

Comments:

This issue and another one I submitted yesterday has caused me a LOT of grief. I was trying to write a simple export/import routine so that I could export a particular table from one databae and import it into another. This should have been a 30 minute job, but I cannot set a boolean field in SQL to "undefined" or that long CF error string. I've had to waste time trying to find workarounds for these and I am now in my 2nd day with this. This should not be that hard. While in this particular case this seems to be more of a bug than my other issue, I want to stress here as well, Coldfusion should NOT change values of my variables for me. There is no justifiable reason to do that.
Comment by External U.
13995 | November 14, 2013 11:07:11 AM GMT
Additionally, in my example provided, I passed true as a second parameter to serializeJson(). This does not materially change things, the values are still correct, it simply allows you to more easily inspect the results later in the example code by grouping the field with it's values
Comment by External U.
13996 | November 14, 2013 11:09:25 AM GMT
This is even worse than I first thought. When, for the variables that are affected by this, if you try and even USE them, for instance in my above example, the field pages.status was one that had this issue, if the current record had null, it will display either the CF error string or simply undefined, but worse is that if you try and use that variable, like say fix the value, you get an error that the variable is not defined EVEN though if you cfdump the structure that contains the variable it is displayed and present as a variable. So now to work around this I will essentially have to add an isDefined check, why quite possibly will return true or even worse add a try/catch block to deal with it. This is really untennable
Comment by External U.
13997 | November 14, 2013 11:29:45 AM GMT
[subscribe] //////////////////
Vote by External U.
13999 | November 18, 2013 03:38:29 PM GMT
Reserialization of deserialized Data gives the same result as first time serialization. cfdump output "undefined array element" is for null object. So this does not seems to be an issue as per deserialization feature.
Comment by Awdhesh K.
13998 | February 22, 2014 01:10:47 AM GMT