Class: JsonbSerializer

Inherits:
Object
  • Object
show all
Defined in:
app/serializers/jsonb_serializer.rb

Overview

Serialize JSONB.

Class Method Summary collapse

Class Method Details

.dump(obj) ⇒ JSON

Dump an object to JSON.

Parameters:

  • obj (Object)

    any object

Returns:

  • (JSON)

    the JSON representation of the object



9
10
11
# File 'app/serializers/jsonb_serializer.rb', line 9

def self.dump(obj)
  obj.to_json
end

.load(json) ⇒ Hash

Load a JSON string as a Hash.

Parameters:

  • json (String)

    a JSON string

Returns:

  • (Hash)

    a hash with symbol as well as string keys



17
18
19
20
# File 'app/serializers/jsonb_serializer.rb', line 17

def self.load(json)
  h = JSON.parse(json) if json.instance_of?(String)
  HashWithIndifferentAccess.new(h)
end