aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorJon Moss <me@jonathanmoss.me>2017-08-17 13:43:43 -0400
committerJon Moss <me@jonathanmoss.me>2017-08-17 13:45:19 -0400
commit835246e622dc0431af3cb951db22ef78876006af (patch)
tree02163694a17cf48557354960016ad8c78924dd74 /guides
parent25ccf03af248a402a668295ebd2dcadd656c0f1d (diff)
downloadrails-835246e622dc0431af3cb951db22ef78876006af.tar.gz
rails-835246e622dc0431af3cb951db22ef78876006af.tar.bz2
rails-835246e622dc0431af3cb951db22ef78876006af.zip
Add note about JSON/JSONB serialization changes
The initial commit (efaa6e4f79d457c2cdd08cbc56d63bc972a6993c) that changed this behavior was intended to be a minor change, but ended up becoming a large-ish breaking change within Active Record. This is because instead of only JSON encoding `Hash`es or `Array`s in `#serialize`, we now encode all values passed in. This is an issue if you're passing in a `String`, that has already been transformed from a `Hash` to a `String`, since your data is now being double encoded. Unfortunately, the change was included in one of the v5.0.0 beta releases, and it is too late to revert without huge ripple effects. Thus, all we can do is update the documentation (via this commit), and add some test coverage (coming soon in a PR) for the new behavior. Please note that in the documentation I talk about deserialization, not about serialization, where the actual change occurred. This is because you won't notice any changes in serialized data until you try and deserialize it. Also to make the change itself (confusing until you read through everything multiple times) easier to understand. Related #27788, #25594, #26101, #24234, #28292, #28285, #28285, and probably others. [ci skip]
Diffstat (limited to 'guides')
-rw-r--r--guides/source/upgrading_ruby_on_rails.md9
1 files changed, 9 insertions, 0 deletions
diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md
index 49a0584d51..651b86275a 100644
--- a/guides/source/upgrading_ruby_on_rails.md
+++ b/guides/source/upgrading_ruby_on_rails.md
@@ -397,6 +397,15 @@ When using Ruby 2.4, you can preserve the timezone of the receiver when calling
ActiveSupport.to_time_preserves_timezone = false
+### Changes with JSON/JSONB serialization
+
+In Rails 5.0, how JSON/JSONB attributes are serialized and deserialized changed. Now, if
+you set a column equal to a `String`, Active Record will no longer turn that string
+into a `Hash`, and will instead only return the string. This is not limited to code
+interacting with models, but also affects `:default` column settings in `db/schema.rb`.
+It is recommended that you do not set columns equal to a `String`, but pass a `Hash`
+instead, which will be converted to and from a JSON string automatically.
+
Upgrading from Rails 4.1 to Rails 4.2
-------------------------------------