diff options
author | Godfrey Chan <godfreykfc@gmail.com> | 2014-07-15 08:43:18 -0700 |
---|---|---|
committer | Godfrey Chan <godfreykfc@gmail.com> | 2014-07-15 08:43:18 -0700 |
commit | a66aeb84e215c8a6e365a7fd0197c5703a14f241 (patch) | |
tree | e7fc06a0499ba62d089fc36a4d5ea4a1d17e9e48 /activerecord/lib/active_record/attribute_methods | |
parent | dffc6a43f4df05039693380c5cd2bd8762fb0382 (diff) | |
download | rails-a66aeb84e215c8a6e365a7fd0197c5703a14f241.tar.gz rails-a66aeb84e215c8a6e365a7fd0197c5703a14f241.tar.bz2 rails-a66aeb84e215c8a6e365a7fd0197c5703a14f241.zip |
Revert "Revert "Merge pull request #16059 from jenncoop/json-serialized-attr""
This reverts commit 6f3c64eeb1dc8288dae49f114aaf619adc7dcb7f.
Conflicts:
activerecord/CHANGELOG.md
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/serialization.rb | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/serialization.rb b/activerecord/lib/active_record/attribute_methods/serialization.rb index 734d94865a..264ce2bdfa 100644 --- a/activerecord/lib/active_record/attribute_methods/serialization.rb +++ b/activerecord/lib/active_record/attribute_methods/serialization.rb @@ -37,7 +37,12 @@ module ActiveRecord # serialize :preferences, Hash # end def serialize(attr_name, class_name_or_coder = Object) - coder = if [:load, :dump].all? { |x| class_name_or_coder.respond_to?(x) } + # When ::JSON is used, force it to go through the Active Support JSON encoder + # to ensure special objects (e.g. Active Record models) are dumped correctly + # using the #as_json hook. + coder = if class_name_or_coder == ::JSON + Coders::JSON + elsif [:load, :dump].all? { |x| class_name_or_coder.respond_to?(x) } class_name_or_coder else Coders::YAMLColumn.new(class_name_or_coder) |