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

Problem with serializeJSON -- truncates embedded objects

New Here ,
Apr 15, 2012 Apr 15, 2012

Copy link to clipboard

Copied

It appears that serializeJSON will truncate embedded arrays of objects. This came up while refactoring an ajax app and it took a while to trace down as I thought I must have done something wrong in refactoring somewhere.

I eventually found out that the implicit serialization that was being done by a "remote" method of an object that has a property containing an array of other objects seems to truncate anything more than the first two elements of the embedded array.

Here are some files that demonstrate the problem running the dev version 9.01 on a Windows 7 desktop.

Index.cfm generates an array of objects, then adds the array to a property of ttl_message object and serializes both the array itself (which works fine) and the ttl_message object (which results in the first two elements of the embedded array being serialized but the second two being set to "").

Application.cfm:

component {

 

          this.name="serialize";

          this.sessionmanagement="Yes";

          this.setclientcookies="Yes";

          this.sessiontimeout="#createTimeSpan(0,0,60,0)#";

          this.applicationtimeout="#createTimeSpan(1,0,0,0)#";

          this.ormEnabled = false;

}

ttl_Assignment.cfc

component ttl_Assignment

          accessors="true"

          persistent="false" {

          property string name;

  property string description;

 

          function init( obj ) {

                    if( IsDefined("obj") ) {

                              for( var p in obj) {

                                        variables

= obj

;

                              }

                    }

          }

 

}

ttl_Message.cfc

component ttl_Message

          accessors="true"

          persistent="false"   {

 

          property string name;

   

    property any payload;

          public any function init( string name){

                    if( isStruct( "name" ) ) {

                              populate(name);

                    } else {

                              setName( name );

                    }

 

                    return this;

          }

}


Index.cfm

<cfscript>

 

          // make some new assignments

          a = new ttl_Assignment( {"name"="foo","description"="descript here"} );

          b = new ttl_Assignment( {"name"="boo","description"="descript 2"} );

          c = new ttl_Assignment( {"name"="boo","description"="descript 3"} );

          d = new ttl_Assignment( {"name"="boo","description"="descript 4"} );

 

          // put them into an array

          arr = [a,b,c,d];

 

          // create a message

          mess = new ttl_Message( "here is the message" );

 

          // add the array to the message

          mess.setPayload( arr );

 

          writedump( arr );                                                            // dump the array

          writedump( serializeJSON(arr) );                    // serialize the array

          writedump( mess );                                                            // dump the message

          writedump( serializeJSON(mess) );                    // serialize the message

 

</cfscript>

TOPICS
Advanced techniques

Views

2.1K

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 Expert ,
Apr 23, 2012 Apr 23, 2012

Copy link to clipboard

Copied

It is a known bug (ID=83836). Cumulative Hotfix 2 of ColdFusion 9.0.1 addresses this issue, among others.

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
New Here ,
Apr 23, 2012 Apr 23, 2012

Copy link to clipboard

Copied

Here is my experience before and after Hotfix 2:

1. Still see similar error in ORM as the original poster described (nested objects can only serialize the first two, the rest are serialized as empty objects)

2. The objects are kind of correctly serialized as empty objects instead of empty string (behavior before hotfix 2)

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 Expert ,
Apr 24, 2012 Apr 24, 2012

Copy link to clipboard

Copied

My advice to David is to install the hot fix and find out for himself. In any case, the hot fix resolves plenty of other issues besides, some of them quite serious.

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
New Here ,
Apr 24, 2012 Apr 24, 2012

Copy link to clipboard

Copied

Glad to hear prompt reply. We did have hot fix 2 installed, and saw some improvements. There is still some problem getting only the first two elements in array JSON serialized. And here is what we found after some try and error:

1. only applicable to JSON serialization (CFDUMP can show the whole data without any problem);

2. only have problem with ORM returns (which are java objects), we created Coldfusion structs similar to the original post, and that data can be serialized correctly in hotfix 2

3. only happens when the array is embedded in another parent object. Top level array can be serialized correctly

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
Engaged ,
Apr 25, 2012 Apr 25, 2012

Copy link to clipboard

Copied

I'm seeing precisely the same behavior: when serializing ORM objects, only the first 2 elements in an embedded array have data, while additional array elements are rendered as "{}".

I know there is a bug filed for this already (https://bugbase.adobe.com/index.cfm?event=bug&id=3042650), but am hoping someone has ideas for workarounds.

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
Engaged ,
Apr 25, 2012 Apr 25, 2012

Copy link to clipboard

Copied

AND...is apparently still an issue in CF10. *sigh*

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 Expert ,
Apr 26, 2012 Apr 26, 2012

Copy link to clipboard

Copied

LATEST

existdissolve wrote:

AND...is apparently still an issue in CF10. *sigh*

It is sad to hear that the issue has resurfaced in ColdFusion 10. I have voted for it in the bugbase.

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