Status/Resolution/Reason: Closed/Withdrawn/AsDesigned
Reporter/Name(from Bugbase): Josh Souza / Josh Souza (Josh_Souza_ViaWest)
Created: 02/22/2013
Components: Core Runtime
Versions: 10.0
Failure Type:
Found In Build/Fixed In Build: Final /
Priority/Frequency: Normal / All users will encounter
Locale/System: English / Win All
Vote Count: 5
Problem Description: When you deserialize a json structure with 'null' values, such as: {"text":null} instead of a blank string or otherwise, the documentation states: The JSON null value becomes the string null.
In previous versions of Coldfusion (confirmed with 8 and 9) it becomes either a blank string or the actual text "null". However in CF10 it becomes 'undefined' in a very odd way.
You end up with a structure with all of the keys that were passed in, but they may not have values at all. So if you did: <cfset test=DeserializeJSON('{"good":"string","bad":null}>
You would be able to cfoutput: #test.good# but you would receive an error if you tried to output #test.bad#, because the value doesn't exist.
StructKeyExists reports that the value does not exist, yet StructKeyList still returns the key.
Steps to Reproduce:
Put the following code into a test page in CF9 and CF10 and observe the differences.
<cfset testString='{"description":null,"testText":"nothing"}'>
<cfset ts=DeserializeJson(testString)>
<cfoutput>
This is before I fix anything. Here is the given string: #testString#
<br>This is what it deserializes into
<cfdump var="#ts#">
<br>These are the struct key list entries: #StructKeyList(ts)#
<br>This is the result of StructKeyExists(ts,"description"): #StructKeyExists(ts,"description")#
</cfoutput>
<cfloop list="#StructKeyList(ts)#" index="key">
<cfif not StructKeyExists(ts,key)>
<cfset ts[key]="">
</cfif>
</cfloop>
<cfoutput>
<br>This is after I fix things.
<br>These are the struct key list entries: #StructKeyList(ts)#
<br>This is the result of StructKeyExists(ts,"description"): #StructKeyExists(ts,"description")#
<br>And the final resulting deserialized struct:
<cfdump var="#ts#">
</cfoutput>
<cfabort>
Actual Result: CF error when attempting to dereference structure values that have keys.
Expected Result: You should be able to dereference all structure keys that are returned from StructKeyList
Any Workarounds:
By performing a loop such as the following after all dereferences, it kinda works around the problem for us (replicating CF9 behavior)
<cfloop list="#StructKeyList(ts)#" index="key">
<cfif not StructKeyExists(ts,key)>
<cfset ts[key]="">
</cfif>
</cfloop>
----------------------------- Additional Watson Details -----------------------------
Watson Bug ID: 3505249
External Customer Info:
External Company:
External Customer Name: Josh_Souza_ViaWest
External Customer Email:
External Test Config: CF10 in Windows and Linux
Attachments:
Comments: