views:

98

answers:

1

I have a JRuby class which contains an instance variable that is a Java object. As you may know, JRuby has a lot of trouble serializing Java objects, and therefore I would just like to skip over the object.

How might this be achieved?

A: 

You probably would have to write your own custom Marshal function to exclude the Java instance variable. For a very simple example, see http://www.linuxtopia.org/online_books/programming_books/ruby_tutorial/Reflection_ObjectSpace_and_Distributed__Ruby_Custom_Serialization_Strategy.html

You would need to change the code to custom Marshal all but the Java instance: there is no generic functionality to exclude, only define the whole marshal method on class level. You could use reflection to get a list of instance variables, remove your unwanted ones and marshal the remaining instance vars. Not that difficult, but not a one-liner any more.

Rutger Nijlunsing