Copy link to clipboard
Copied
ColdFusion 11 offers a new feature to preserve the case of struct keys during JSON serialization. Trouble is it does not work for me (OSX 10.9.4).
The documentation mentions 2 ways to get this working (although it is supposed to be on by default).
Neither of these work. Stopping and Starting ColdFusion does not help.
No matter what, I always get the keys converted to UPPERCASE, just like in CF10 and earlier.
This would be a great feature to have working. Is it a bug? Has anyone else got it working?
Andrew Culver
I found the problem.
I had an extra line that I guess was causing an error sometimes so something anyway I removed that line of code from the application.cfc and its working perfectly now.
That line was before THIS.serialization.preserveCaseForQueryColumn= true so I think it was bombing before it got to that line what is weird is that it sometimes worked.
Copy link to clipboard
Copied
I have the same issue but for me sometimes it is converted to upper case and sometimes not.
so my code sometimes works and sometimes doesn't.
Copy link to clipboard
Copied
Hi Michael.
Could you post the snippet that works intermittently for you?
There have been issues reported with the flag in the past, but with the latest updates applied, you should not be seeing an issue.
Copy link to clipboard
Copied
My CFC:
component {
remote function getEmployeeList( ) returnFormat="JSON"{
var queryObj1 = new query(datasource="MyDataSource");
var Obj1Result = queryObj1.execute(
sql="SELECT id, firstName, lastName, gender, isActive, address1, address2
FROM Employee
ORDER BY firstName ASC");
var Obj1QueryResult = Obj1Result.getResult();
var theJSON = {};
theJSON = SerializeJSON(Obj1QueryResult,'struct');
return theJSON;
}
}
And in the Application.cfc I added these tags and also I enabled it in the cold fusion administrator :
<cfset THIS.serialization.preserveCaseForStructKey = true />
<cfset THIS.serialization.preserveCaseForQueryColumn= true />
I am running cold fusion 2016 with the latest update.
Copy link to clipboard
Copied
Michael,
Your snippet uses a database, and the only key that would matter in this scenario is preserveCaseForQueryColumn.
Here's a snippet that demonstrates struct key preservation.
Application.cfc
this.serialization.preserveCaseForStructKey = "true"
remote function func2( ) returnFormat="JSON"{
simpleStruct = structnew();
simpleStruct.Name="Camel Case";
simpleStruct.COMPANY="All Caps";
simpleStruct.CItY="Mixed";
theJSON = SerializeJSON(simpleStruct,'struct');
return theJSON;
}
A recompilation is required for this setting to work. You could do a minor edit on the CFC if you are turning the setting on / off very frequently. You could also clear template / component / query cache as applicable.
Can I know what database you are running?
Copy link to clipboard
Copied
sql server 2014.
so am I doing smoothing wrong ?
Copy link to clipboard
Copied
I just rechecked on SQLServer 2014, and the following flag is expected to return case sensitive column names.
this.serialization.preserveCaseForQueryColumn = "true";
Do try to clear cache after the flag is flipped.
Copy link to clipboard
Copied
I Already have both on.
<cfset THIS.serialization.preserveCaseForStructKey = true />
<cfset THIS.serialization.preserveCaseForQueryColumn= true />
Copy link to clipboard
Copied
Was the cache cleared? Can you try providing true in quotes ("true")
Copy link to clipboard
Copied
I found the problem.
I had an extra line that I guess was causing an error sometimes so something anyway I removed that line of code from the application.cfc and its working perfectly now.
That line was before THIS.serialization.preserveCaseForQueryColumn= true so I think it was bombing before it got to that line what is weird is that it sometimes worked.
Copy link to clipboard
Copied
Just curious.. what was the code that was breaking?
V/r,
^ _ ^
Copy link to clipboard
Copied
<cfset THIS.preserveCaseForQueryColumn= true >
Copy link to clipboard
Copied
So, wait.. you had both THIS.preserveCaseForQueryColum and THIS.serialization.preserveCaseForQueryColumn?
V/r,
^ _ ^
Copy link to clipboard
Copied
Yes.
Copy link to clipboard
Copied
Don't forget to mark your answer as correct. Just in case someone else has the same issue.
V/r,
^ _ ^
Copy link to clipboard
Copied
Thanks, but I am not the original person that started this thread.
I just had the same issue.
I can't mark it as correct.
Copy link to clipboard
Copied
D'OH! I wasn't paying attention.
Copy link to clipboard
Copied
looks like this was not the problem because i am still having the same issue.
it works 60% of the time but not always
Copy link to clipboard
Copied
To quote one of the funniest TV programmes ever:
"Have you tried turning it off and then on, again?"
https://img.devrant.com/devrant/rant/r_218195_67rKL.jpg
V/r,
^ _ ^