• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

incorrect type inferrence when returning JSON from a cfc?

New Here ,
Feb 27, 2009 Feb 27, 2009

Copy link to clipboard

Copied

So, I have a CF function inside a cfc file that queries my SQL database and then returns the CF query object. One of the database fields is an nvarchar field contains a bunch of check numbers, some of which have leading zeros.

The example I have used is a field containing the string "02":
If I use cfdump, it shows up correctly as 02.

If I call the cfc directly from my browser and ask it for wddx, I get the correct result <field name='CHECKNUMBER'><string>02</string></field>

If I call the cfc directly from my browser and ask for json, I get 2.0 back. WRONG.

Is CF8 just naively guessing the datatype when is does JSON serialization? CF query objects have types in them and it does it correctly in the other two cases so it obviously has the correct type information available. I ended up retrieving WDDX instead of JSON and deserializing it into a Javascript object using the wddxDes.js file from www.openwddx.org. I also find it strange and annoying that the matching wddx.js file from the same web site is included with the standard installation of Coldfusion but the deserializer part is not. Has anyone else run into these problems or found a solution that works without extending Coldfusion with outside help? This just seems like a straight-up bug in CF8 to me.
TOPICS
Advanced techniques

Views

283

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 28, 2009 Feb 28, 2009

Copy link to clipboard

Copied

> If I call the cfc directly from my browser and ask for json, I get 2.0 back.
> WRONG.
> [...]
>This just seems like a straight-up bug
> in CF8 to me.

Agreed.

This can be easily demonstrated with this code:

<cfscript>
q = queryNew("col1", "CF_SQL_VARCHAR");
queryAddRow(q);
querySetCell(q, "col1", javacast("String", "02"));

j = serializeJson(q);
writeOutput(j);
</cfscript>

This outputs:
{"COLUMNS":["COL1"],"DATA":[[2.0]]}

If one changes the string to " 20", it outputs:
{"COLUMNS":["COL1"],"DATA":[[" 02"]]}

So it's definitely not paying attention to the data-type of the string. CF
has a habit of mucking things up like this.

I think you should raise a bug with Adobe.

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 28, 2009 Feb 28, 2009

Copy link to clipboard

Copied

LATEST
>> If I call the cfc directly from my browser and ask for json, I get 2.0 back.
>> WRONG.
>> [...]
>>This just seems like a straight-up bug
>> in CF8 to me.

This might help:
http://jsonutil.riaforge.org/

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation