Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@WaKeMaTTa
Created June 16, 2016 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WaKeMaTTa/cee2b4e8e435f30bc32ad6e494caf93e to your computer and use it in GitHub Desktop.
Save WaKeMaTTa/cee2b4e8e435f30bc32ad6e494caf93e to your computer and use it in GitHub Desktop.
app/serializers/hash_serializer.rb
# app/serializers/hash_serializer.rb
class HashSerializer
def self.dump(hash)
hash.to_json
end
def self.load(hash)
hash = ActiveSupport::JSON.decode(hash) if hash.is_a? String
(hash || {}).with_indifferent_access
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment