nesquena / rabl

General ruby templating with json, bson, xml, plist and msgpack support
http://blog.codepath.com/2011/06/27/building-a-platform-api-on-rails/
MIT License
3.65k stars 335 forks source link

Support JRuby #544

Open dblock opened 10 years ago

dblock commented 10 years ago

Was looking at https://github.com/LTe/grape-rabl/pull/22 which is failing on JRuby. Rabl doesn't support JRuby, oj and msgpack both fail to install, to start.

fred commented 10 years ago

rabl does work on Jruby, only the OJ gem is MRI only, it uses native C extensions.

in Jruby and mongoid without OJ gem, we get

{"id"=>{"$oid"=>"53a1506ff12a9c47ba000e29"}}

instead of

{"id"=>"53a1506ff12a9c47ba000e29"}

we can also use this in the rabl files, but it's kind of a pain in the ass to do it.

node(:id) {|obj| obj.id.to_s }
dblock commented 10 years ago

This has been discussed in https://groups.google.com/forum/#!msg/mongoid/MaXFVw7D_4s/T3sl6Flg428J.

Monkey patch:

module BSON
  class ObjectId
    def as_json(options = {})
      to_s
    end

    def to_bson_key(encoded = ''.force_encoding(BINARY))
      to_s.to_bson_key(encoded)
    end
  end
end
dblock commented 10 years ago

@fred How does Rabl work on JRuby though? Check out git@github.com:LTe/grape-rabl.git and run tests on JRuby. You will get the failure above. Maybe I am missing something?

toshe commented 10 years ago

This is killing us. @dblock , take a look at #471 I don't even know where to start.

dblock commented 9 years ago

Confirmed JRuby bug, https://github.com/jruby/jruby/issues/3009#issuecomment-108091994, made some progress to setting up JRuby tests for Rabl for when that's fixed (or trying to find a workaround), https://github.com/dblock/rabl/tree/jruby, but I ran into #632.