An Architect's View

CFML, Clojure, Software Design, Frameworks and more...

An Architect's View

Scope != Struct

April 28, 2004 ·

An interesting thread on BACFUG's mailing list just highlighted an interesting difference between a scope and a struct. Now, we all know that scopes are really structs but they behave like them in so many ways, it's easy to forget. Nolan Erck was trying to pass
scope to a web service method that expected a struct. He got an obscure Axis error saying that the argument (
) could not be serialized. He found that if he duplicated
scope, it worked. He later found that if he tried to use
instead, it didn't work and he got the same serializable error.
To really see why, you need to dig into Java a little bit: for any variable (and many expressions) in ColdFusion you can find out the underlying Java type by calling
on it:
form.getClass().getName()? #form.getClass().getName()#
structNew().getClass().getName()? #structNew().getClass().getName()#
If you run that code, you'll get this output:
form.getClass().getName()? coldfusion.filter.FormScope
structNew().getClass().getName()? coldfusion.runtime.Struct
duplicate(form).getClass().getName()? coldfusion.runtime.Struct
structCopy(form).getClass().getName()? coldfusion.runtime.LocalScope
We can see from this that
is not a struct even it plays one on TV. We can also see that
does return a struct but
does not.
This subtle difference doesn't matter when you're passing
directly to a function that expects a struct because CFMX understands the magic behind a scope, but when you pass it to a web service, you're relying on Axis to be able to serialize the object... and Axis does not understand the magic.

Tags: coldfusion

0 responses