ColdFusion 9 JSON Bug

This post is more than 2 years old.

This one is a doozy. I hope it gets fixed by a hot fix rather than the next "dot" update. Bjorn Jensen gets credit for finding it. I ran into it myself yesterday when working on my blog entry. If you have a CFC that returns numeric data and uses a returnType of numeric, then ColdFusion will throw an error. Here is one example of code that will throw the error:

<cffunction name="getX" access="remote" returntype="numeric"> <cfargument name="id" type="any"> <cfreturn> </cffunction>

I then entered this URL to test: http://localhost/test.cfc?method=getx&id=1&returnformat=json. The error was:

java.lang.Double cannot be cast to java.lang.String

The fix is to simply change the returnType to string (or any). You can find more detail (and vote for a fix!) at the public bug tracker:

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by Stacey Abshire posted on 10/19/2009 at 4:12 PM

I'm a coldfusion noob, so maybe that skews my thoughts here, but it looks to me, that you are returning a value from a variable whose type is not clearly defined, though you are defining a specific return type for the function. Changing the argument type from "any" to "numeric" would fix this and be more correct, right? Just my two cents.

Comment 2 by Raymond Camden posted on 10/19/2009 at 4:17 PM

I wrote this blog entry early, so maybe it's my fault, but you do get the point, right? Yes, numeric _is_ better, but it throws a bug, so we can't use it in CF9. That's the whole point of this blog entry, to say that returnType=numeric will break under CF9 (with returnFormat=json).

Comment 3 by Stacey Abshire posted on 10/19/2009 at 4:21 PM

I'm using 8 here, but what I was referring to was that you have

<cfargument name="id" type="any">

instead of

<cfargument name="id" type="numeric">

Does that change the outcome for you?

Comment 4 by Edward Smith posted on 10/19/2009 at 4:45 PM

I think this is just another manifestation of a widespread JSON encoding bug with datatypes.

I reported a version of this quite a while ago, but was disappointed to have it not fixed in 9.

Comment 5 by Jeffrey Gordon posted on 10/19/2009 at 4:50 PM

CF has had casting bugs for some time now and they do not seem to want to fix them. I reported awhile back (I think around CF5) a cast error that was thrown if you tried to serialize a query recordset containing a clob to wddx. As far as I know that bug had not been fixed, course my last check of that bug was in CF8.

Comment 6 by Raymond Camden posted on 10/19/2009 at 5:31 PM

Stacey... am I not being clear? I'm reporting a bug about type=numeric. That's the point of this article. type=numeric will throw an error in CF9. I switched to type=any as a workaround for the bug.

Comment 7 by John Hodorowicz posted on 10/19/2009 at 6:31 PM

Stacey's referring to difference between the argument (id) type being "any" and the function returntype "numeric" (since the function is just returning the value of the argument, id).

I'm not sure how or if this affects the bug.

Comment 8 by Raymond Camden posted on 10/19/2009 at 6:39 PM

Ah duh. Afaik, it has zero impact here. The main factor is the _returnType_ only.

Comment 9 by Asha posted on 10/20/2009 at 9:58 AM

Hey Ray,

We are aware and we have fixed this issue, we will soon be releasing the fix,will let you know once the technote is out.

Comment 10 by Raymond Camden posted on 10/20/2009 at 3:17 PM

Awesome. Thank you for the update!

Comment 11 by abhijit posted on 11/1/2009 at 10:19 PM


I need to load data in a dynamic table using javascript(json).

I am using the cfajaxproxy tag and also serializejson function to get data from cfc method but dont know how to load the data in the javascript table.........

Comment 12 by Raymond Camden posted on 11/1/2009 at 11:50 PM

You would need to work with the result to "write" the rows out back to the table. In jQuery it would be a matter of creating an HTML string and just appending it to the table.

Comment 13 by Doug posted on 1/13/2010 at 1:02 AM

Hey Ray, Have you heard if this bug has been fixed yet for 9? I just ran into it today and it's been driving me nuts. I don't see anything on Adobe's website about any hotfixes for 9 yet, but perhaps there's some top-secret link that you're aware of maybe?

Comment 14 by Raymond Camden posted on 1/13/2010 at 1:04 AM

I'm not aware of a fix.

Comment 15 by Doug posted on 1/13/2010 at 1:08 AM


Comment 16 by Gregory Matthews posted on 2/4/2010 at 1:09 PM

I was wondering what the heck was going on. I was able to pinpoint the cause after a lot of frustration and did exactly what you describe here.

Oh, and I also reverted back to CF8 until CF9 works through some of these types of kinks!


Comment 17 by Dave Phipps posted on 4/19/2010 at 1:22 AM

I am still seeing this error even when I have applied the latest cf 9 hotfix. I have also changed the returntype to any but still see the error. If I change the returnformat from 'json' to 'plain' in the call to the remote method then it returns the correct value.

I can't easily change all remote calls to use plain as some return more than just a simple value.

Any other suggestions/fixes available apart from going back to cf8!

Comment 18 by Raymond Camden posted on 4/19/2010 at 1:34 AM

I don't believe that hotfix mentions a fix for this, does it? If you don't see it listed then obviously it isn't fixed yet.

Comment 19 by Dave Phipps posted on 4/19/2010 at 1:44 AM

Apparently it is: 80375 (6th item in list) on this page:

Comment 20 by Raymond Camden posted on 4/19/2010 at 1:52 AM

Interesting. Did you restart after applying the hotfix?

Comment 21 by Leah Schuster posted on 6/24/2010 at 1:00 AM

This hotfix was a lifesaver. It took care of the JSON bug and the CFC mapping error.

Comment 22 by Dave Phipps posted on 6/24/2010 at 2:11 AM

Nothing like a speedy follow up - I logged the problem with Adobe and it appears that there was a problem with the hotfix jar I was downloading from their site. The engineer sent me a fresh copy and the file size was different. Reapplied the new larger hotfix file - restarted cf and all is working again.