Class: MultiJson::Adapters::OkJson

Inherits:
MultiJson::Adapter show all
Includes:
ConvertibleHashKeys
Defined in:
lib/multi_json/adapters/ok_json.rb

Direct Known Subclasses

Nsjsonserialization

Constant Summary

ParseError =
::MultiJson::OkJson::Error

Instance Method Summary collapse

Methods inherited from MultiJson::Adapter

defaults, dump, load

Methods included from Options

#default_dump_options, #default_load_options, #dump_options, #dump_options=, #load_options, #load_options=

Instance Method Details

#dump(object, options = {}) ⇒ Object



19
20
21
# File 'lib/multi_json/adapters/ok_json.rb', line 19

def dump(object, options={})
  ::MultiJson::OkJson.valenc(stringify_keys(object))
end

#load(string, options = {}) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/multi_json/adapters/ok_json.rb', line 11

def load(string, options={})
  string = string.read if string.respond_to?(:read)
  result = ::MultiJson::OkJson.decode("[#{string}]").first
  options[:symbolize_keys] ? symbolize_keys(result) : result
rescue ArgumentError # invalid byte sequence in UTF-8
  raise ParseError
end