Title:
Deserializing a a json string where some variables have values of null changes those values
| View in TrackerStatus/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: