How to convert JavaObject to YAML format?


#1

Hello,

I would like to store Java object to YAML format using JRuby.
I’ll show you the code below.

Java

public class LearinigJRubyAndJavaIntegration {
public static void main(String[] args) throws Exception{
BSFManager manager = new BSFManager();
Map<String, Object> map = new HashMap<String, Object>();
map.put(“name”, “test”);
manager.registerBean(“conf”, map);
InputStreamReader reader = new
InputStreamReader(LearningJRuby.class.getResource(“write_yaml.rb”).openStream());
manager.exec(“ruby”, “(java)”, -1, -1,
IOUtils.getStringFromReader(reader));
}
}

write_yaml.rb

require ‘yaml’
require ‘java’
conf = $bsf.lookupBean(“conf”)
puts YAML.dump(conf)

provided

— !ruby/object:Java::JavaUtil::HashMap
java_object: !ruby/object:Java::JavaObject {}

Environment

JDK 1.5.0_16
OS: Linux
JRuby: 1.1.6

Is it possible to convert JavaObject to YAML format?


Hiroki K.
removed_email_address@domain.invalid


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email