Skip to main content
Participating Frequently
July 24, 2012
Question

Serialization of inherited CFC properties doesn't work

  • July 24, 2012
  • 1 reply
  • 574 views

I didn't find anything on this problem, though it's hard for me to believe that it hasn't been encountered and addressed somewhere.

The title says it -- though the biggest problem is that the serialization fails when trying to send over the wire to a CF backend. I have heard that with FlashRemoting there is a workaround, but don't know what to do in CF. Here are some files that demonstrate it.

application.cfm

component {

          this.sessionmanagement = 'true';

          this.sessionTimeout = createTimeSpan(0,2,0,0);

          this.name = "SE";

}

Component files (some settings are hold overs from the ORM-enabled app they come from)

Job.cfc:

component

          entityname="Job"

    persistent="false"

    table="tbl_job"

    output="false"

    accessors="true"

    discriminatorcolumn="entity_type"

     {

          /**

          * @column id

          * @fieldtype id

          * @10825876 increment

          * @3514369 true

          * @Setter false

          */

          property int id;

          // discriminator column

          /**

          * @10986680 false

          * @7605746 false

          */

          property entity_type;

   

          // **** Common Properties

 

          /**

          * @column name

          * @length 255

          */

          property string name;

 

          /**

          * @column description

          * @length 400

          */

          property string description;

   

          /**

          * @displayname init

          * @description init method

          * @8071592 false

          */

          public any function init() {

                    return this;

          }

   

}

Campaign.cfc:

component

          entityname="Campaign"

    persistent="false"

    table="tbl_job"

    output="false"

    accessors="true"

    discriminatorvalue="campaign"

    extends="Job" {

 

          /**

          * @column camp_prop

          * @length 255

          */

          property string camp_prop;

 

}

Index.cfm:

<cfscript>

          c = new serializationError.Campaign();

          writeoutput( "New, empty campaign: ");

          writedump( c );

 

          c.setName("Campaign name");

          c.setDescription("This is my description");

 

          writeoutput( "<br />Campaign with inherited properties set which don't show up in the dump: ");

          writedump( c );

          writeoutput("<br />Here is the value of 'name', an inherited property: '" & c.getName() & "'<br />");

          writeoutput( "<br /><br />Here is the serialized version of the object (which shows up empty): <br />" & serializeJSON( c ) );

          c.setcamp_prop("Here is a property in the campaign");

          writeoutput("<br /><br />Here is dump after a non-inherited property has been set: ");

          writedump( c );

          writeoutput( "<br />Here the serialized version (which has the non-inherited value, but no inherited values):<br /> " & serializeJSON( c ) );

</cfscript>

    This topic has been closed for replies.

    1 reply

    Participating Frequently
    July 26, 2012

    I mentioned the problem to Jason Aden. As he was running into the same problem (with some slight variations) on a project he was working on, he coded something to address it. I'm going to integrate his solution into the project I'm working on in the next day or so and will report back on it, but figured I'd give the reference here as it looks like this should solve the problem for now (eventually should be fixed in CF). His posting is at:

    http://www.justcodefaster.com/blog/2012/07/toserializable-method-for-coldfusion-objects/