Skip to content

Instantly share code, notes, and snippets.

@nvquanghuy
Created February 9, 2014 05:51
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 nvquanghuy/8894931 to your computer and use it in GitHub Desktop.
Save nvquanghuy/8894931 to your computer and use it in GitHub Desktop.
class JsonCoder
# Called to deserialize data to ruby object.
def load(data)
d = Oj.load(data || '{}')
d.recursive_symbolize_keys
end
# Called to convert from ruby object to serialized data.
def dump(obj)
obj.kind_of?(String) ? obj : Oj.dump(obj, mode: :compat)
end
end
class Car < ActiveRecord::Base
serialize :options, JsonCoder.new
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment