<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: ColdFusion null Gotcha</title>
	<atom:link href="http://www.barneyb.com/barneyblog/2011/04/27/coldfusion-null-gotcha/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.barneyb.com/barneyblog/2011/04/27/coldfusion-null-gotcha/</link>
	<description>Thoughts, rants, and even some code from the mind of Barney Boisvert.</description>
	<lastBuildDate>Thu, 11 Sep 2014 09:58:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2011/04/27/coldfusion-null-gotcha/comment-page-1/#comment-392734</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Fri, 02 Aug 2013 04:14:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1650#comment-392734</guid>
		<description>I&#039;m sorry, I assumed you were referring to CF structs, not JSON packets.  The impetus for my original post was the inability to differentiate between &lt;code&gt;null&lt;/code&gt;s in JSON, exactly as your packets illustrate.</description>
		<content:encoded><![CDATA[<p>I'm sorry, I assumed you were referring to CF structs, not JSON packets.  The impetus for my original post was the inability to differentiate between <code>null</code>s in JSON, exactly as your packets illustrate.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: D</title>
		<link>https://www.barneyb.com/barneyblog/2011/04/27/coldfusion-null-gotcha/comment-page-1/#comment-392689</link>
		<dc:creator>D</dc:creator>
		<pubDate>Thu, 01 Aug 2013 22:28:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1650#comment-392689</guid>
		<description>That didn&#039;t work (using CF9; is it different in CF10?).  The following returned &lt;code&gt;YES&lt;/code&gt; for both tests, and keys in both contained the string value &lt;code&gt;&quot;null&quot;&lt;/code&gt;:

&lt;pre&gt;
&lt;cfscript&gt;
map1 = DeserializeJSON(&#039;{&quot;name&quot; : null}&#039;);
map2 = DeserializeJSON(&#039;{&quot;name&quot; : &quot;null&quot;}&#039;);
&lt;/cfscript&gt;

&lt;cfoutput&gt;
key &#039;name&#039; exists in map1:  #structKeyExists(map1, &#039;name&#039;)#
key &#039;name&#039; exists in map2:  #structKeyExists(map2, &#039;name&#039;)#
&lt;/cfoutput&gt;
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>That didn't work (using CF9; is it different in CF10?).  The following returned <code>YES</code> for both tests, and keys in both contained the string value <code>"null"</code>:</p>
<pre>
&lt;cfscript&gt;
map1 = DeserializeJSON('{"name" : null}');
map2 = DeserializeJSON('{"name" : "null"}');
&lt;/cfscript&gt;

&lt;cfoutput&gt;
key 'name' exists in map1:  #structKeyExists(map1, 'name')#
key 'name' exists in map2:  #structKeyExists(map2, 'name')#
&lt;/cfoutput&gt;
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2011/04/27/coldfusion-null-gotcha/comment-page-1/#comment-392686</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Thu, 01 Aug 2013 22:07:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1650#comment-392686</guid>
		<description>D,

Assuming you deserialize into &#039;&lt;code&gt;map&lt;/code&gt;&#039;, then &lt;code&gt;#structKeyExists(map, &#039;name&#039;)#&lt;/code&gt; will return &#039;&lt;code&gt;false&lt;/code&gt;&#039; for the first and &#039;&lt;code&gt;true&lt;/code&gt;&#039; for the second.</description>
		<content:encoded><![CDATA[<p>D,</p>
<p>Assuming you deserialize into '<code>map</code>', then <code>#structKeyExists(map, 'name')#</code> will return '<code>false</code>' for the first and '<code>true</code>' for the second.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: D</title>
		<link>https://www.barneyb.com/barneyblog/2011/04/27/coldfusion-null-gotcha/comment-page-1/#comment-392685</link>
		<dc:creator>D</dc:creator>
		<pubDate>Thu, 01 Aug 2013 22:05:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1650#comment-392685</guid>
		<description>So is there a way to test the difference between {&quot;name&quot; : null} and {&quot;name&quot; : &quot;null&quot;} after deserialization?</description>
		<content:encoded><![CDATA[<p>So is there a way to test the difference between {"name" : null} and {"name" : "null"} after deserialization?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2011/04/27/coldfusion-null-gotcha/comment-page-1/#comment-255458</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Sun, 01 May 2011 00:09:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1650#comment-255458</guid>
		<description>Ben, that&#039;s exactly the problem which manifested this post.  It was in another developer&#039;s app, inverted, and was a normal struct (not the arguments scope), but that&#039;s the gist of it.  CF rather screwed up in making null behave both ways.  It was pretty much masked until recently, but the simple fact is that if you run on the JRE you have nulls, and any JRE language needs to acknowledge that fact.</description>
		<content:encoded><![CDATA[<p>Ben, that's exactly the problem which manifested this post.  It was in another developer's app, inverted, and was a normal struct (not the arguments scope), but that's the gist of it.  CF rather screwed up in making null behave both ways.  It was pretty much masked until recently, but the simple fact is that if you run on the JRE you have nulls, and any JRE language needs to acknowledge that fact.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2011/04/27/coldfusion-null-gotcha/comment-page-1/#comment-255457</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Sun, 01 May 2011 00:08:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1650#comment-255457</guid>
		<description>Matt, I disagree.  Historically, a null value was &quot;missing&quot; in CFML parlance, and rightfully so.  In CF9, Adobe added isNull to differentiate the two cases (because it&#039;s needed for using Hibernate), but there&#039;s a LOT of code sitting around which equates a null value to missing.

Your test about JSON serialization is flawed.  Obviously the serialized version of a null will be the string &quot;null&quot;.  That&#039;s stipulated by the JSON spec.  And that&#039;s what your test was checking.  For purposes of comparison, I&#039;ve rewritten it here:

&lt;pre&gt;StringBuilder sb = new StringBuilder();
new JavaScriptSerializer().Serialize(null, sb);
assert sb.ToString() == null; // false - will be &quot;null&quot;
&lt;/pre&gt;

I don&#039;t know C#, but your test needs to be something like this (forgive the erroneous types and syntax):

&lt;pre&gt;StringBuilder sb = new StringBuilder();
new JavaScriptSerializer().Serialize(null, sb);
Object theValue = new JavaScriptDeserializer().Deserialize(sb.toString());
assert theValue == null; // true
&lt;/pre&gt;

You have to deserialize to get back to the environment - the serialized format is always strings.</description>
		<content:encoded><![CDATA[<p>Matt, I disagree.  Historically, a null value was "missing" in CFML parlance, and rightfully so.  In CF9, Adobe added isNull to differentiate the two cases (because it's needed for using Hibernate), but there's a LOT of code sitting around which equates a null value to missing.</p>
<p>Your test about JSON serialization is flawed.  Obviously the serialized version of a null will be the string "null".  That's stipulated by the JSON spec.  And that's what your test was checking.  For purposes of comparison, I've rewritten it here:</p>
<pre>StringBuilder sb = new StringBuilder();
new JavaScriptSerializer().Serialize(null, sb);
assert sb.ToString() == null; // false - will be "null"
</pre>
<p>I don't know C#, but your test needs to be something like this (forgive the erroneous types and syntax):</p>
<pre>StringBuilder sb = new StringBuilder();
new JavaScriptSerializer().Serialize(null, sb);
Object theValue = new JavaScriptDeserializer().Deserialize(sb.toString());
assert theValue == null; // true
</pre>
<p>You have to deserialize to get back to the environment &#8211; the serialized format is always strings.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben Nadel</title>
		<link>https://www.barneyb.com/barneyblog/2011/04/27/coldfusion-null-gotcha/comment-page-1/#comment-254964</link>
		<dc:creator>Ben Nadel</dc:creator>
		<pubDate>Wed, 27 Apr 2011 21:45:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1650#comment-254964</guid>
		<description>Another interesting thing about NULL struct keys is that they are still available during struct iteration (ie. collection loop). I ran into that once when looping over non-required CFArgument keys -- they were in the loop but caused a problem when I tried to reference them.</description>
		<content:encoded><![CDATA[<p>Another interesting thing about NULL struct keys is that they are still available during struct iteration (ie. collection loop). I ran into that once when looping over non-required CFArgument keys &#8212; they were in the loop but caused a problem when I tried to reference them.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Osbun</title>
		<link>https://www.barneyb.com/barneyblog/2011/04/27/coldfusion-null-gotcha/comment-page-1/#comment-254946</link>
		<dc:creator>Matt Osbun</dc:creator>
		<pubDate>Wed, 27 Apr 2011 18:21:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1650#comment-254946</guid>
		<description>Treating a null value of a struct as if it were missing is dangerous, I think, and should probably be reported as a bug.  I have a hard time imagining how that behavior could be right.

With the serialization, however, I&#039;m not sure that&#039;s a bug. Or even all that unusual or unexpected. I did a quick test in C#:

			StringBuilder sb = new StringBuilder();
			new JavaScriptSerializer().Serialize(null, sb);

At the end of this, sb will have the string value of &quot;null&quot;, and sb.ToString() == null will evaluate as false. Which makes sense, really. JSON serializes an object and returns a string value. If a null value didn&#039;t have some kind of string representation, I think it would break the JSON formatting.</description>
		<content:encoded><![CDATA[<p>Treating a null value of a struct as if it were missing is dangerous, I think, and should probably be reported as a bug.  I have a hard time imagining how that behavior could be right.</p>
<p>With the serialization, however, I'm not sure that's a bug. Or even all that unusual or unexpected. I did a quick test in C#:</p>
<p>			StringBuilder sb = new StringBuilder();<br />
			new JavaScriptSerializer().Serialize(null, sb);</p>
<p>At the end of this, sb will have the string value of "null", and sb.ToString() == null will evaluate as false. Which makes sense, really. JSON serializes an object and returns a string value. If a null value didn't have some kind of string representation, I think it would break the JSON formatting.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
