Problem with serializeJSON -- truncates embedded objects
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>
