Class: MultiJson::Adapters::Oj

Inherits:
MultiJson::Adapter show all
Includes:
OjCommon
Defined in:
lib/multi_json/adapters/oj.rb

Overview

Use the Oj library to dump/load.

Defined Under Namespace

Classes: ParseError

Instance Method Summary collapse

Methods inherited from MultiJson::Adapter

defaults, dump, inherited, 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 = {}) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Serialize a Ruby object to JSON

Examples:

Serialize object to JSON

adapter.dump({key: "value"}) #=> '{"key":"value"}'

Parameters:

  • object (Object)

    object to serialize

  • options (Hash) (defaults to: {})

    serialization options

Returns:

  • (String)

    JSON string



61
62
63
# File 'lib/multi_json/adapters/oj.rb', line 61

def dump(object, options = {})
  ::Oj.dump(object, prepare_dump_options(options))
end

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parse a JSON string into a Ruby object

Examples:

Parse JSON string

adapter.load('{"key":"value"}') #=> {"key" => "value"}

Parameters:

  • string (String)

    JSON string to parse

  • options (Hash) (defaults to: {})

    parsing options

Returns:

  • (Object)

    parsed Ruby object



47
48
49
50
# File 'lib/multi_json/adapters/oj.rb', line 47

def load(string, options = {})
  options[:symbol_keys] = options[:symbolize_keys]
  ::Oj.load(string, options)
end