I want to thank those of you who read my rant and added your opinions, questions and corrections (Thanks Nic loosely typed of course :) )
Letting of steam certainly helps and getting feedback helps focus too.
Thanks Kai, I will attempt to clarify my problem with SerializeJSON.
Russ S. I will definitely look at those projects as serializejson for my project is not usable.
The Problem (As I see It)The problem with CF being loosely typed is that there is no way for me to force a string. If you are working with user generated content, lets say a blog or a cms, and the user decides to name a page as "9999999999999999E+10", this value will be stored as such in the database, because the database field is also a string.
When I read this data out of the database and save it in a structure or variable coldfusion interprets that value as a number but leaves it untouched e.g. doesn't change its format. Returning the structure as JSON the page title is transformed from the previous value to 9.999999999999999E25. As I mentioned in my previous post the two numbers are mathematically identical, the strings however are completely different!
The user is expecting to see "9999999999999999E+10" therefore not expected behavior === bug. Ok, with such a user entry you may be considering that to be an edge case, and I would tend to agree that the likelyhood that a user chooses that exact number as the title for a page is remote, but the problem remains.
Queries are no help
A simple test with CF's built in queries proves that serializeJson ignores the column type and outputs the VarChar as Numeric.
<cfset q = queryNew("title","VarChar")>
Although the number has not been changed it is still being sent back to the calling JS function as a number. Once JS parses the JSON our original string, which is now a number, is naturally interpreted as one by JS, which results in a value of : 123456789012345680000 !== "123456789012345678901"
The Right way?
As for the right way to handle this with a loosely typed language such as CF it's no easy task, some assumptions have to be made. I would prefer as little assumptions as possible be made about my data. I can live with dates and boolean assumptions (but then CF needs to send back true/false for all functions that return boolean instead of some with yes/no).
But the problem with numbers is when is a number a number and when is it a string? The database knows the data types that are stored. But as we saw above if I serialize a query it seems to ignore the data types.
To prevent the problems with when is a number a number and when is it a string, the only "real" solution, in my opinion, is return numbers as strings.
No recent entries.