You can't serialize an entire CFC directly, because it's made up of more
than just data. The way I'd do it is to have a serialize() and
deserialize() method in your CFC. The first will take the CFC's internal
state, wrap it up in whatever way you deem fit, and return a WDDX packet of
that data, which can be stored however. The deserialize() method would take
that WDDX packet, and revert the CFC to the stored state. If you're using
6.1, you should be able to just do the whole variables scope.
<cfcomponent name="Serializer">
<cffunction name="serialize" ...>
<cfset var result = "" />
<cfwddx action="cfml2wddx" input="#variables#" output="result" />
<cfreturn result />
</cffunction>
<cffunction name="deserialize" ...>
<cfargument name="data" ... />
<cfset var temp = "" />
<cfset var i = "" />
<cfwddx action="wddx2cfml" input="#arguments.data#" output="temp" />
<cfloop collection="#temp#" item="i">
<cfset variables[i] = temp[i] />
</cfloop>
</cffunction>
<!--- other methods --->
</cfcomponent>
To use it, you'd do something like this:
<cfscript>
one = createObject("component", "Serializer");
one.init();
one.doSomething();
wddx = one.serialize();
two = createObject("component", "Serializer");
two.deserialize(wddx);
// now 'two' has the exact same state as 'one'
</cfscript>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Behalf Of Justin Balog
> Sent: Tuesday, September 23, 2003 3:34 PM
> To: '[EMAIL PROTECTED]'
> Subject: [CFCDev] Serialize?
>
>
>
> I don't even know if I am using the correct term? Is there a quick way to
> serialize a cfc, say in to a WDDX packet? Basically, I want to take an
> instance of a cfc and write it to a file in a meaningful way (i.e. WDDX or
> XML) in case there is a dB error or ODBC connection failure. Any thoughts
> on how to do this without having to call all the getters/setters of the
> object itself.
>
>
> Thanks,
>
> Justin
> ----------------------------------------------------------
> You are subscribed to cfcdev. To unsubscribe, send an email
> to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev'
> in the message of the email.
>
> CFCDev is run by CFCZone (www.cfczone.org) and supported
> by Mindtool, Corporation (www.mindtool.com).
>
> An archive of the CFCDev list is available at
www.mail-archive.com/[EMAIL PROTECTED]
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev'
in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]