1
0

json_with_indifferent_access.rb 364 B

123456789101112
  1. class JsonWithIndifferentAccess
  2. def self.load(json)
  3. ActiveSupport::HashWithIndifferentAccess.new(JSON.parse(json || '{}'))
  4. rescue JSON::ParserError
  5. Rails.logger.error "Unparsable JSON in JsonWithIndifferentAccess: #{json}"
  6. { 'error' => 'unparsable json detected during de-serialization' }
  7. end
  8. def self.dump(hash)
  9. JSON.dump(hash)
  10. end
  11. end