# Can't Marshal.dump a Java object (from using Rjb)

**URL:** <https://www.ruby-forum.com/t/cant-marshal-dump-a-java-object-from-using-rjb/88048>\
**Category:** Ruby\
**Created:** [March 7, 2007, 7:13pm UTC](https://www.ruby-forum.com/t/cant-marshal-dump-a-java-object-from-using-rjb/88048 "2007-03-07T19:13:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 7, 2007, 7:13pm UTC](https://www.ruby-forum.com/t/cant-marshal-dump-a-java-object-from-using-rjb/88048/1 "2007-03-07T19:13:28Z")

</div>

All,

I have a Ruby object that actually encapsulates a Java object - I got it  
by using Rjb to talk to a Java library.

When I attempt to marshal it, I get the following error:

“can’t dump anonymous class”

If Rjb returned a named class instead of an anonymous one, would I then  
be able to marshal it?

BTW, why can’t anonymous classes be dumped?

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 7, 2007, 10:05pm UTC](https://www.ruby-forum.com/t/cant-marshal-dump-a-java-object-from-using-rjb/88048/2 "2007-03-07T22:05:00Z")

</div>

On Thu, 8 Mar 2007 03:13:33 +0900, Wes G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> If Rjb returned a named class instead of an anonymous one, would I then  
> be able to marshal it?

No, not at this time. It isn’t even technically feasible to implement  
unless the Java object being wrapped belongs to a class which supports  
Java serialization (i.e. implements java.io.Serializable).

> BTW, why can’t anonymous classes be dumped?

A class name is required by Ruby’s marshal format, since otherwise there  
would be no way to determine which class to use when loading the  
marshalled object. Remember that a dumped object may be loaded in a  
different interpreter instance than the one that dumped it.

-mental
