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 collapse

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, _ = {}) ⇒ Object



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

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

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



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

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