Skip to content

Instantly share code, notes, and snippets.

@Fivell
Created September 14, 2012 11:08
Show Gist options
  • Save Fivell/3721335 to your computer and use it in GitHub Desktop.
Save Fivell/3721335 to your computer and use it in GitHub Desktop.
jruby java objects to_json with Gson
require 'gson-1.6.jar'
class GsonBuilder
include_package "com.google.gson"
def initialize
@gson = GsonBuilder.new.setFieldNamingPolicy(FieldNamingPolicy::LOWER_CASE_WITH_UNDERSCORES).serializeNulls().create()
end
def to_json(obj)
@gson.to_json(obj)
end
end
gson = Gson.new
obj = someJavaObject.new
p gson.to_json(obj)
@gwang
Copy link

gwang commented Feb 24, 2014

seems to have a bug, should be "class Gson" instead of GsonBuilder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment