All things Marathon, Marathonite, Java and GUI Test automation, scripting and whatever is useful for test automation projects.
All things Marathon, Marathonite, Java and GUI Test automation, scripting and whatever is useful for test automation projects.
CATEGORIES
BOOKMARKS
JRuby: Passing array of array of string to java
December 31st, 2008
Working on assert_content implementation for JRuby. And straight-away headed into a road block. The call to assert_content looks like this:
assert_content('component', [['R1C1', 'R1C2', 'R1C3'], ['R2C1', 'R2C2', 'R2C3']])
This function from ruby should call a java function:
assertContent(String componentName, String[][] content);
Now it is easy enough in JRuby to convert an array of strings to java array of strings:
['hello'].to_java :String #=> String[]
But converting a array of array of strings is not that straight forward. After a bit of hacking, I found this way.
[['r1c1', 'r1c2'], ['r2c1', 'r2c2']].to_java([].to_java(:String).class) #=> String[][]
Is there any better way of doing this?
This entry was posted on Wednesday, December 31st, 2008 at 2:01 am and is filed under JRuby, Marathon. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
(C) Jalian Systems 2008 | contact
A posting to jruby-users suggested pre 1.1.3
[['r1c1', 'r1c2'], ['r2c1', 'r2c2']].map {|ary| ary.to_java(:String)
with 1.1.4+, the suggestion was
[['r1c1', 'r1c2'], ['r2c1', 'r2c2']].to_java java.lang.String[]
Which brings me to my question… Do you plan to update jruby version with the next 2.0 release?
2.0b4 will ship with JRuby 1.1.5. Jython I am still keeping at 2.2.1 and removing separate model for 2.5 versions.
You can use earlier/later versions by setting the Home in project settings.
– KD
Great ideas, is there a place to elaborate on this all?
This is quite a up-to-date info. I’ll share it on Twitter.