Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

CHANGELOG for JSON refactor + added back the `encode_big_decimal_as_string` option with warning #13060

Merged
merged 1 commit into from

3 participants

@chancancode
Owner

/cc @jeremy

@chancancode chancancode referenced this pull request in chancancode/activesupport-json_encoder
Closed

Track rails/rails#13060 #1

activesupport/lib/active_support/json/encoding.rb
@@ -113,6 +114,26 @@ class << self
# in +Object#to_json+ and +ActiveSupport::JSON.encode+.
attr_accessor :json_encoder
+ ENCODE_BIG_DECIMAL_AS_NUMBERS_DEPRECATION_MESSAGE = \
+ "The JSON encoder in Rails 4.1 no longer supports encoding BigDecimals as JSON numbers. " \
+ "If your application depends on this, you should install the 'activesupport-json_encoder' " \
+ "gem to restore the old behavior. In the future, the related configuration option, " \
+ "ActiveSupport.encode_big_decimal_as_string, will be removd from Rails."
@jeremy Owner
jeremy added a note

removed

@chancancode Owner

fixed, also changed "install the xxx gem" => "add the xxx gem to your Gemfile"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
activesupport/CHANGELOG.md
@@ -1,3 +1,23 @@
+* Removed the old pure-Ruby JSON encoder and switched to a new encoder based on the built-in JSON
+ gem.
+
+ Support for encoding `BigDecimal` as a JSON number, as well as defining custom `encode_json`
+ methods to control the JSON output has been **removed from core**. BigDecimals will be encoded
+ as `String`s by default.
+
+ The old encoder has been extracted into the `activesupport-json_encoder` gem. Installing that
+ gem will bring back the ability to encode `BigDecimal`s as numbers as well as `encode_json`
+ support.
+
+ The related configuration `ActiveSupport.encode_big_decimal_as_string` is deprecated in core
+ to ensure a smooth upgrade path. Reading from this option will always return true. Reading the
+ option or setting it to true will trigger a depreactation warnning. Setting it to false will

depreactation warnning => deprecation warning

Also it might be good to wrap true/false in backticks for highlighting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
activesupport/test/json/encoding_test.rb
@@ -172,6 +172,24 @@ def test_wide_utf8_roundtrip
assert_equal "
@chancancode Owner

Oops, will fix the name on next push

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
activesupport/lib/active_support/json/encoding.rb
@@ -113,6 +114,26 @@ class << self
# in +Object#to_json+ and +ActiveSupport::JSON.encode+.
attr_accessor :json_encoder
+ ENCODE_BIG_DECIMAL_AS_NUMBERS_DEPRECATION_MESSAGE = \
+ "The JSON encoder in Rails 4.1 no longer supports encoding BigDecimals as JSON numbers. " \
+ "If your application depends on this, you should add the 'activesupport-json_encoder' " \
+ "gem to your Gemfile to restore the old behavior. In the future, the related configuration " \
+ "option, ActiveSupport.encode_big_decimal_as_string, will be removed from Rails."

How about:

The JSON encoder in Rails 4.1 no longer supports encoding BigDecimals as JSON numbers.
If your application depends on this, you should add the 'activesupport-json_encoder'
gem to your Gemfile to restore the old behavior, otherwise you can safely remove the 
related 'active_support.encode_big_decimal_as_string' configuration from your application.

So that we tell people what to do in all cases, wdyt?

@chancancode Owner

:+1:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@chancancode
Owner

Updated with the suggestions from @carlosantoniodasilva. I kept the changelog entry in its original position when rebasing, partly because that's the order we merged these commits, and partly because I don't have to compete with future additions to the changelog :)

activesupport/lib/active_support/json/encoding.rb
@@ -113,6 +114,31 @@ class << self
# in +Object#to_json+ and +ActiveSupport::JSON.encode+.
attr_accessor :json_encoder
+ def encode_big_decimal_as_string=(as_string)
+ message = \
+ "The JSON encoder in Rails 4.1 no longer supports encoding BigDecimals as JSON numbers. Instead, " \
+ "the new enocder will always encode them as strings.\n\n" \

encoder (in both messages)

@chancancode Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
activesupport/lib/active_support/json/encoding.rb
@@ -113,6 +114,31 @@ class << self
# in +Object#to_json+ and +ActiveSupport::JSON.encode+.
attr_accessor :json_encoder
+ def encode_big_decimal_as_string=(as_string)
+ message = \
+ "The JSON encoder in Rails 4.1 no longer supports encoding BigDecimals as JSON numbers. Instead, " \
+ "the new enocder will always encode them as strings.\n\n" \
+ "You are seeing this error because you have 'active_support.encode_big_decimal_as_string' in " \
+ "your configuration file. If you have been setting this to true, you can safely remove it from " \
+ "your configuration. Otherwise, you should add the 'activesupport-json_encoder' gem to your " \

two spaces after gem

@chancancode Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@chancancode chancancode referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
activesupport/lib/active_support/json/encoding.rb
((7 lines not shown))
+ "the new encoder will always encode them as strings.\n\n" \
+ "You are seeing this error because you have 'active_support.encode_big_decimal_as_string' in " \
+ "your configuration file. If you have been setting this to true, you can safely remove it from " \
+ "your configuration. Otherwise, you should add the 'activesupport-json_encoder' gem to your " \
+ "Gemfile in order to restore this functionality."
+
+ raise NotImplementedError, message
+ end
+
+ def encode_big_decimal_as_string
+ message = \
+ "The JSON encoder in Rails 4.1 no longer supports encoding BigDecimals as JSON numbers. Instead, " \
+ "the new encoder will always encode them as strings.\n\n" \
+ "You are seeing this error because you are trying to check the value of the related configuration, " \
+ "'active_support.encode_big_decimal_as_string'. For now, this option will always be true. In the " \
+ "future, it will be removed from Rails, so you should stop checking its value."

I think it might be interesting to talk about the gem here too? If people are checking this, they might have a reason for doing so?

@chancancode Owner

Good call, updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
activesupport/lib/active_support/json/encoding.rb
((6 lines not shown))
+ "The JSON encoder in Rails 4.1 no longer supports encoding BigDecimals as JSON numbers. Instead, " \
+ "the new encoder will always encode them as strings.\n\n" \
+ "You are seeing this error because you have 'active_support.encode_big_decimal_as_string' in " \
+ "your configuration file. If you have been setting this to true, you can safely remove it from " \
+ "your configuration. Otherwise, you should add the 'activesupport-json_encoder' gem to your " \
+ "Gemfile in order to restore this functionality."
+
+ raise NotImplementedError, message
+ end
+
+ def encode_big_decimal_as_string
+ message = \
+ "The JSON encoder in Rails 4.1 no longer supports encoding BigDecimals as JSON numbers. Instead, " \
+ "the new encoder will always encode them as strings.\n\n" \
+ "You are seeing this error because you are trying to check the value of the related configuration, " \
+ "'active_support.encode_big_decimal_as_string'. If your application depend on this option, you should " \

If your application depends

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@carlosantoniodasilva

Minor comment, I think we're good to :shipit:

@carlosantoniodasilva carlosantoniodasilva merged commit 6e905e2 into rails:master
@carlosantoniodasilva

Thanks :heart:

@chancancode
Owner
@benja83 benja83 referenced this pull request from a commit in benja83/toyotakataboard-relational
@benja83 benja83