Created
February 9, 2014 05:51
-
-
Save nvquanghuy/8894931 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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