I am writing simple DSL in JRuby, for a Java library. Some object created in JRuby are passed to the Java code, processed and returned back to JRuby. I am using JRuby 1.7.8.
At some point while processing the objects created in JRuby need to be serialized and deserialized by the Java library (to perform deep cloning). Here is where the problem occurs. Appart from String and a plain Object it seems not possible to serialize in Java objects created in JRuby.
For example, while serializing to an empty Hash object I get:
IOError: org.jruby.RubyHash$RubyHashEntry
load at org/jruby/RubyKernel.java:1103
at /usr/local/rvm/gems/jruby-1.7.8/bin/pry:23
eval at org/jruby/RubyKernel.java:1123
(root) at /usr/local/rvm/gems/jruby-1.7.8/bin/jruby_executable_hooks:15
for [ "asd" ]
i get:
IOError: org.jcodings.specific.UTF8Encoding
load at org/jruby/RubyKernel.java:1103
at /usr/local/rvm/gems/jruby-1.7.8/bin/pry:23
eval at org/jruby/RubyKernel.java:1123
(root) at /usr/local/rvm/gems/jruby-1.7.8/bin/jruby_executable_hooks:15
I found some posts about it (e.g. here and here), but they are all quite old and do not explain anything about future plans. It seems to me an important limitation when considering integration of Ruby and Java.
Now I'm serializing my objects to JSON on Ruby side, and deserializing them from JSON when they are returned. It works, but this comes with significant efficiency penalty.
So the questions are:
- Is it possible to somehow make Ruby objects Serializable in Java? If not, will it be possible in near future?
- Does anybody now a better (faster) workaround then the JSON solution I desribed above?
EDIT:
This spec in JRuby repo suggests that there is something going on concerning the serialization. However, its still 2 years old and does not explain serialization policy of other objects.