Skip to content

Instantly share code, notes, and snippets.

@skippy
Created May 3, 2015 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skippy/89cafb280017d52a582c to your computer and use it in GitHub Desktop.
Save skippy/89cafb280017d52a582c to your computer and use it in GitHub Desktop.
google-protobuf under jruby has broken JSON encoding
# google-protobuf/master
require 'google/protobuf'
pool = Google::Protobuf::DescriptorPool.new
pool.build do
add_message 'ProtoMsg' do
repeated :msg_string, :string, 1
end
end
ProtoMsg = pool.lookup('ProtoMsg').msgclass
pm = ProtoMsg.new
pm.msg_string += ['foo', 'bar']
pm #=> <ProtoMsg: msg_string: ["foo", "bar"]>
puts ProtoMsg.encode_json(pm)
# {"msg_string":"#<Google::Protobuf::RepeatedField:0x1725dc0f>"}
# my patch
# ......
pm #=> <ProtoMsg: msg_string: ["foo", "bar"]>
puts ProtoMsg.encode_json(pm)
# {"msg_string":["foo","bar"]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment