Class: SpreeCmCommissioner::StoreMetadata::ResilientJSONCoder

Inherits:
Object
  • Object
show all
Defined in:
app/models/concerns/spree_cm_commissioner/store_metadata.rb

Overview

Custom JSON coder that gracefully handles corrupted JSON data

Class Method Summary collapse

Class Method Details

.dump(obj) ⇒ Object



42
43
44
# File 'app/models/concerns/spree_cm_commissioner/store_metadata.rb', line 42

def self.dump(obj)
  JSON.dump(obj)
end

.load(json) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'app/models/concerns/spree_cm_commissioner/store_metadata.rb', line 46

def self.load(json)
  return {} if json.blank?

  begin
    JSON.parse(json)
  rescue JSON::ParserError, TypeError
    # If JSON is corrupted, return empty hash instead of raising
    {}
  end
end