class MultiJson::Adapters::Gson
Use the gson.rb library to dump/load.
Constants
- ParseError
Public Instance Methods
dump(object, options = {})
click to toggle source
Serialize a Ruby object to JSON
@api private @param object [Object] object to serialize @param options [Hash] serialization options @return [String] JSON string
@example Serialize object to JSON
adapter.dump({key: "value"}) #=> '{"key":"value"}'
# File lib/multi_json/adapters/gson.rb, line 32 def dump(object, options = {}) ::Gson::Encoder.new(options).encode(object) end
load(string, options = {})
click to toggle source
Parse a JSON string into a Ruby object
@api private @param string [String] JSON string to parse @param options [Hash] parsing options @return [Object] parsed Ruby object
@example Parse JSON string
adapter.load('{"key":"value"}') #=> {"key" => "value"}
# File lib/multi_json/adapters/gson.rb, line 19 def load(string, options = {}) ::Gson::Decoder.new(options).decode(string) end