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 arguments.id>
</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: http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbugtracker/main.html#bugId=80375.
Archived Comments
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.
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).
I'm using 8 here, but what I was referring to was that you have
<cfargument name="id" type="any">
<cfreturn arguments.id>
instead of
<cfargument name="id" type="numeric">
<cfreturn arguments.id>
Does that change the outcome for you?
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.
http://cfbugs.adobe.com/cfb...
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.
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.
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.
Ah duh. Afaik, it has zero impact here. The main factor is the _returnType_ only.
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.
Awesome. Thank you for the update!
Hi,
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.........
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.
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?
I'm not aware of a fix.
Bummer.
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!
G.
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!
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.
Apparently it is: 80375 (6th item in list) on this page: http://kb2.adobe.com/cps/82...
Interesting. Did you restart after applying the hotfix?
This hotfix was a lifesaver. It took care of the JSON bug and the CFC mapping error.
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.