[英]JRuby: cannot convert instance of class org.jruby.RubyObject to class java.time.Instant
I'm developing on a Ruby on rails (Rails 3.2.22.4) application. 我正在开发Ruby on Rails(Rails 3.2.22.4)应用程序。 Ruby is JRuby (jruby1.7.x). Ruby是JRuby(jruby1.7.x)。
I'm calling a RESTful Java service from this rails application. 我正在从该Rails应用程序调用RESTful Java服务。 The request of calling java service contains java.time.Instant
, I tried to use ruby Time
, DateTime
, and use java_import
directly to create java.time.Instant, but none of them worked. 调用java服务的请求包含java.time.Instant
,我尝试使用ruby Time
, DateTime
,并直接使用java_import
来创建java.time.Instant,但是它们都不起作用。 I got 我有
TypeError: cannot convert instance of class org.jruby.RubyObject to class java.time.Instant TypeError:无法将org.jruby.RubyObject类的实例转换为java.time.Instant类
Is there any ruby class, or other work around I should use to address this type conversion problem? 是否有红宝石类,或者我应该使用其他解决方法来解决此类型转换问题?
Thanks! 谢谢!
JRuby 9.2 supports these by default when doing Time/DateTime#to_java
在执行Time/DateTime#to_java
时,JRuby 9.2默认支持这些Time/DateTime#to_java
so when JRuby's Java Integration sees a java.time.Instant
parameter it will auto-convert a Ruby Time
(or DateTime
) object. 因此,当JRuby的Java Integration看到java.time.Instant
参数时,它将自动转换Ruby Time
(或DateTime
)对象。
for (old) JRuby 1.7 this obviously won't work, but creating a java.time.Instant
type directly really should have worked, so keep looking into that. 对于(旧)JRuby 1.7,这显然不起作用,但是直接创建java.time.Instant
类型确实应该起作用,因此请继续研究。 its hard to tell what failure are you having with that. 很难说出这是什么失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.