Skip to main content
Participating Frequently
April 15, 2012
Question

Problem with serializeJSON -- truncates embedded objects

  • April 15, 2012
  • 1 reply
  • 2430 views

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>

This topic has been closed for replies.

1 reply

BKBK
Community Expert
Community Expert
April 23, 2012

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

Participant
April 23, 2012

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)

BKBK
Community Expert
Community Expert
April 24, 2012

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.