Class: IntegerKeyHashSerializer

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

Overview

Serializer for JSONB columns that store { integer_key => value } hashes,
typically { item_id => quantity } in Packing#contents.

PostgreSQL JSONB always deserializes object keys as strings. This serializer
normalises them back to integers on load so callers can use integer IDs
naturally (e.g. contents[item.id]) without string/integer fallback hacks.

Handles both shapes the contents column can take:
Hash — single-box { item_id => qty, … }
Array — multi-box [{ item_id => qty }, { item_id => qty }, …]

Class Method Summary collapse

Class Method Details

.dump(value) ⇒ Object



12
13
14
# File 'app/serializers/integer_key_hash_serializer.rb', line 12

def self.dump(value)
  value
end

.load(raw) ⇒ Object



16
17
18
# File 'app/serializers/integer_key_hash_serializer.rb', line 16

def self.load(raw)
  normalize(HashSerializer.load(raw))
end