Created
September 14, 2012 11:08
-
-
Save Fivell/3721335 to your computer and use it in GitHub Desktop.
jruby java objects to_json with Gson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
seems to have a bug, should be "class Gson" instead of GsonBuilder.