tracker issue : CF-4203352

select a category, or use search below
(searches all categories and all time range)
Title:

Applying the function serializeJson() to a struct containing a string whose value is boolean or numeric, removes the string's quotation marks.

| View in Tracker

Status/Resolution/Reason: Closed/Won't Fix/AsDesigned

Reporter/Name(from Bugbase): A. Bakia / ()

Created: 09/24/2018

Components: Serialization

Versions: 2016

Failure Type: Others

Found In Build/Fixed In Build: 2016,0,06,308055 / CF 2018

Priority/Frequency: Normal /

Locale/System: / Windows 7 SP1 64-bit

Vote Count: 0

Problem Description:
When you apply the function serializeJson() to a struct containing a string whose value is boolean or numeric, ColdFusion removes the string's quotation marks. Without quotation marks the result is then a boolean or numerical key. This affects ColdFusion 11 and ColsFusion 2016.

Steps to Reproduce:
Run the following code

<cfscript>
//all the values of the key-value pirs are strings
myStruct={key1="yes",key2="2E3",key3="1.2",key4="myString"};
myStructSerialized=serializeJson(myStruct);
writeDump(myStructSerialized);
</cfscript>

Actual Result:
The output is 

{"KEY2":2E3,"KEY1":true,"KEY4":"myString","KEY3":1.2}

Observe how the values 2E3, true and 1.2 are numerical or boolean

Expected Result:
A JSON result in which every value is a string, that is

{"KEY2":"2E3","KEY1":"yes","KEY4":"myString","KEY3":"1.2"}

Any Workarounds:
Yes.
Use the function setMetadata to set the datatype of each key:

<cfscript>
myStruct={key1="yes",key2="2E3",key3="1.2",key4="myString"};

//Set the datatype of each key
dataType={key1:{type="string"},key2:{type="string"},key3:{type="string"}};
myStruct.setMetadata(dataType);

myStructSerialized=serializeJson(myStruct);
writeDump(myStructSerialized);
</cfscript>

Attachments:

Comments:

Related to CF-4201928
Comment by A. Bakia
29737 | September 24, 2018 09:07:08 PM GMT