[英]How can I make a field transient, so Java objects don't get serialized when using marshal?
I have a JRuby class which contains an instance variable that is a Java object. 我有一个JRuby类,其中包含一个实例变量,该实例变量是Java对象。 As you may know, JRuby has a lot of trouble serializing Java objects, and therefore I would just like to skip over the object.
您可能知道,JRuby在序列化Java对象时遇到很多麻烦,因此我只想跳过该对象。
How might this be achieved? 如何实现?
You probably would have to write your own custom Marshal function to exclude the Java instance variable. 您可能必须编写自己的自定义Marshal函数才能排除Java实例变量。 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
有关一个非常简单的示例,请参见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. 您需要将代码更改为自定义Marshal(除了Java实例之外的所有代码):没有要排除的通用功能,仅在类级别定义整个marshal方法。 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.
没那么困难,但不再是一线好事。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.