Re: serialization of BeanShell objects

Patrick Niemeyer <[email protected]> Tue, 11 Jan 2005 13:54:15 -0600
Newsgroups gmane.comp.java.beanshell.devel
Message-ID <[email protected]>
On Jan 11, 2005, at 12:12 PM, [email protected] wrote:

> Can I serialize beanshell objects? For instance:
>
> f()
> {
>   String s = "hello";
>   return this;
> }
>
> x = f();
>
> ObjectOutputStream out = ....
>
> out.writeObject(x);
>
> In one case, I got a NotSerializeable exception. In another, I got a 
> infite recursion in the Java APIs!

Yes, it should work.  The only catch is that if you don't want to 
serialize the whole interpreter along with it you need to detach the 
object from its namespace.  The BeanShell save() method (which 
serializes objects to files) does this automatically, but you can do it 
directly with:

   x.namespace.prune();

The whole interpreter actually should be serializeable, subject to what 
you put into it of course (if you have a variable referencing a 
non-serializable object then it won't currently work).  But this 
probably hasn't been tested in the 2.0 beta and you may have discovered 
problems.

Thanks,
Pat



-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt