JSON backward Compatibility: Flag to enable CF8 behavior

JSON serialization was
introduced in CF8 for the first time. It was used heavily to serialize CFC and
other CF data objects. In “CumulativeHotfix1 for ColdFusion 9.0.1”, some of its
outstanding issues were fixed. 
Few of issues addressed in hotfix were that of string to number
conversion, and number getting converted to double.

The change in behavior
of JSON serialization, which fixed some of the basic problems of CF developer
at one hand, also had a side effect of breaking old application built on CF8.
Migration from CF8 to later version might require making few changes in the developer’s

To achieve backward
compatibility and to address a scenario where old behavior of JSON
serialization has to be retained, a JVM flag had been introduced at the same
time. If enabled, it would bypass the latest changes for JSON serialization and
fall back to CF8 behavior.

Here I am describing the JVM flag and the way to
enable it. This will bring back the old behavior where a string with leading zero like ‘000’ will be output as 0.0 rather than 000, an invalid number in javascript. Similarly all the number will be retained in double/float format. A number like 1.23E4 will be converted to 12340 and so on. So you can make use of this flag if you have got stuck upgrading to latest CF server.

To achieve the CF8 behavior, one can add a
JVM system property 
json.numberasdouble=true to jvm.config.
It is applicable to  CF “CumulativeHotfix1 for ColdFusion 9.0.1” and
later .

jvm.config file is located at  $CF_HOME/cfusion/bin/jvm.config.
Open the file and you will find “-Djava.awt.headless=true” as one of the entry
in java.args parameters.

Please add the suggested
flag just after former headless entry as  –Djson.numberasdouble=true.