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 developer advocate for HERE Technologies. He focuses on JavaScript, serverless 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