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

Case preservation for struct keys not working

New Here ,
Jul 28, 2014 Jul 28, 2014

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).

  1. In application.cfc, set this.serialization.preservecaseforstructkey = true
  2. In the ColdFusion administrator settings page, check 'Preserve case for Struct keys for Serialization'

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

Views

3.3K

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

correct answers 1 Correct answer

Community Beginner , May 24, 2018 May 24, 2018

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.

Votes

Translate

Translate
Community Beginner ,
May 22, 2018 May 22, 2018

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.

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
Explorer ,
May 23, 2018 May 23, 2018

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.

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
Community Beginner ,
May 23, 2018 May 23, 2018

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.

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
Explorer ,
May 23, 2018 May 23, 2018

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?

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
Community Beginner ,
May 23, 2018 May 23, 2018

Copy link to clipboard

Copied

sql server 2014.

so am I doing smoothing wrong ?

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
Explorer ,
May 24, 2018 May 24, 2018

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. 

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
Community Beginner ,
May 24, 2018 May 24, 2018

Copy link to clipboard

Copied

I Already have both on.

<cfset THIS.serialization.preserveCaseForStructKey = true />

<cfset THIS.serialization.preserveCaseForQueryColumn= true />

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
Explorer ,
May 24, 2018 May 24, 2018

Copy link to clipboard

Copied

Was the cache cleared? Can you try providing true in quotes ("true")

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
Community Beginner ,
May 24, 2018 May 24, 2018

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.

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 ,
May 24, 2018 May 24, 2018

Copy link to clipboard

Copied

Just curious.. what was the code that was breaking?

V/r,

^ _ ^

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
Community Beginner ,
May 24, 2018 May 24, 2018

Copy link to clipboard

Copied

<cfset THIS.preserveCaseForQueryColumn= true >

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 ,
May 24, 2018 May 24, 2018

Copy link to clipboard

Copied

So, wait.. you had both THIS.preserveCaseForQueryColum and THIS.serialization.preserveCaseForQueryColumn?

V/r,

^ _ ^

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
Community Beginner ,
May 25, 2018 May 25, 2018

Copy link to clipboard

Copied

Yes.

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 ,
May 25, 2018 May 25, 2018

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,

^ _ ^

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
Community Beginner ,
May 25, 2018 May 25, 2018

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.

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 ,
May 25, 2018 May 25, 2018

Copy link to clipboard

Copied

D'OH!  I wasn't paying attention. 

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
Community Beginner ,
Dec 31, 2018 Dec 31, 2018

Copy link to clipboard

Copied

LATEST

looks like this was not the problem because i am still having the same issue.

it works 60% of the time but not always

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 ,
May 24, 2018 May 24, 2018

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,

^ _ ^

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