aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/json/encoding.rb
Commit message (Collapse)AuthorAgeFilesLines
* Add support for JSON time_precision to Time and DateTimeAndrew White2014-01-261-0/+1
|
* Rename subsecond_fraction_digits option to time_precisionAndrew White2014-01-261-4/+4
|
* Customize subsecond digits when encoding DateWithTimeParker Selbert2014-01-261-1/+6
| | | | | | | | | | | The subsecond fraction digits had been hardcoded to 3. This forced all timestamps to include the subsecond digits with no way to customize the value. While the subsecond format is part of the ISO8601 spec, it is not adhered to by all parsers (notably mobile clients). This adds the ability to customize the number of digits used, optionally setting them to 0 in order to eliminate the subsecond fraction entirely: ActiveSupport::JSON::Encoding.subsecond_fraction_digits = 0
* JSON: speed up date/time encodingJeremy Kemper2013-12-111-24/+19
| | | | | | | | | | | | | | | | Comparing dates & times with other objects using #== is slow. Internally, it hits #<=> which calls #to_datetime on objects that don't respond to it, so we incur the cost of raising an exception with a possibly-deep backtrace. Cost of #jsonify on a Time object: Calculating ------------------------------------- old 3644 i/100ms new 12652 i/100ms ------------------------------------------------- old 43373.8 (±3.5%) i/s - 218640 in 5.047017s new 173437.6 (±5.2%) i/s - 872988 in 5.047747s
* Added back the `encode_big_decimal_as_string` option with warningGodfrey Chan2013-12-021-0/+27
| | | | | Also added the missing CHANGELOG entry for #12183 @ 80e7552073 and 4d02296cfb.
* EscapedString is also private API [ci skip]Godfrey Chan2013-12-011-1/+1
|
* Make the JSON encoder pluggableGodfrey Chan2013-11-261-2/+8
|
* Removed the Ruby encoder and switched to using the JSON gemGodfrey Chan2013-11-261-52/+72
| | | | | | | | | Got all the tests passing again. Support for `encode_json` has been removed (and consequently the ability to encode `BigDecimal`s as numbers, as mentioned in the previous commit). Install the `activesupport-json_encoder` gem to get it back.
* Removed support for encoding BigDecimal as a JSON numberGodfrey Chan2013-11-261-6/+0
| | | | | | | | | | This is because the new encoder will no longer support encode_json. Therefore our only choice is to return `to_i` or `to_s` in `BigDecimal#as_json`. Since casting a BigDecimal to an integer is most likely a lossy operation, we chose to encode it as a string. Support for encoding BigDecimal as a string will return via the `activesupport-json_encoder` gem.
* Move the JSON extension require statements to the right place.Godfrey Chan2013-11-061-8/+0
| | | | | | | In #12203, the JSON core extensions were moved into the `core_ext` folder. Unfortunately, there are some corresponding requires that were left behind. The problem is partially addressed in #12710, this commit fixes the rest.
* Do not expose internal state in the public encoder API (i.e. as_json)Godfrey Chan2013-11-061-37/+24
| | | | | | | | | | | | | | | See [1] for why this is not a good idea. As part of this refactor, circular reference protection in as_json has been removed and the corresponding error class has been deprecated. As discussed with @jeremy, circular reference error is considered programmer errors and protecting against it is out of scope for the encoder. This is again based on the excellent work by @sergiocampama in #11728. [1]: https://github.com/intridea/multi_json/pull/138#issuecomment-24468223
* Moved AS::JSON::DATE_REGEX as it's only used for decodingGodfrey Chan2013-11-061-3/+0
|
* Require time before monkey-patching itRobin Dupret2013-10-311-1/+0
| | | | | | Same as #12710 but for the time module this time. This time it should fix the Active Model test suite in isolation avoiding a TypeError to be raised about the superclass of the DateTime object.
* Require bigdecimal before monkey-patching itRobin Dupret2013-10-311-1/+0
| | | | | | | | If we try to monkey-patch the class before requiring it, then a "superclass mismatch" (TypeError) error is raised and the build can't run correctly. Fixes #12708
* Moved all JSON core extensions into core_ext/object/jsonGodfrey Chan2013-09-131-195/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | TL;DR The primary driver is to remove autoload surprise. This is related to #12106. (The root cause for that ticket is that json/add defines Regexp#to_json among others, but here I'll reproduce the problem without json/add.) Before: >> require 'active_support/core_ext/to_json' => true >> //.as_json NoMethodError: undefined method `as_json' for //:Regexp from (irb):3 from /Users/godfrey/.rvm/rubies/ruby-2.0.0-p195/bin/irb:16:in `<main>' >> //.to_json => "\"(?-mix:)\"" >> //.as_json => "(?-mix:)" After: >> require 'active_support/core_ext/to_json' => true >> //.as_json => "(?-mix:)" This is because ActiveSupport::JSON is autoloaded the first time Object#to_json is called, which causes additional core extentions (previously defined in active_support/json/encoding.rb) to be loaded. When someone require 'active_support/core_ext', the expectation is that it would add certain methods to the core classes NOW. The previous behaviour causes additional methods to be loaded the first time you call `to_json`, which could cause nasty surprises and other unplesant side-effects. This change moves all core extensions in to core_ext/json. AS::JSON is still autoloaded on first #to_json call, but since it nolonger include the core extensions, it should address the aforementioned bug. *Requiring core_ext/object/to_json now causes a deprecation warnning*
* Remove active_support/json/variable was deprecated.kennyj2013-06-011-1/+0
|
* Merge pull request #10534 from cmaruz/masterRafael Mendonça França2013-05-101-1/+4
|\ | | | | | | | | | | | | Escape of U+2028 and U+2029 in the JSON Encoder Conflicts: activesupport/lib/active_support/json/encoding.rb
| * Added escaping of U+2028 and U+2029 inside the json encoder.Mario Caropreso2013-05-091-3/+6
| | | | | | | | | | | | | | | | | | | | | | U+2028 and U+2029 are allowed inside strings in JSON (as all literal Unicode characters) but JavaScript defines them as newline seperators. Because no literal newlines are allowed in a string, this causes a ParseError in the browser. We work around this issue by replacing them with the escaped version. The resulting JSON is still valid and can be parsed in the browser. This commit has been coauthored with Viktor Kelemen @yikulju
* | Fix syntax error on Ruby 2.0Rafael Mendonça França2013-05-101-2/+4
| | | | | | | | | | Since Ruby 2.0 is UTF-8 by default we need to explictly say that the encoding of this file is US-ASCII
* | Escape multibyte line terminators in JSON encodingzackham2013-04-021-2/+4
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, json/encoding respects the JSON spec (as it should) which disallows \n and \r inside strings, escaping them as expected. Unfortunately, ECMA-262 (Javascript) disallows not only \n and \r in strings, but "Line Terminators" which includes U+2028 and U+2029. See here: http://bclary.com/2004/11/07/#a-7.3 This pull request adds U+2028 and U+2029 to be escaped. # Why?  It's very common to see something like this in a Rails template: <script type="text/javascript">  var posts = <%= @posts.to_json %>; </script> If U+2028 or U+2029 are part of any attributes output in the to_json call, you will end up with an exception. In Chrome: Uncaught SyntaxError: Unexpected token ILLEGAL  # Why not? This is JSON encoding, and the JSON spec is specific about how to  encode strings. U+2028 and U+2029 don't get special treatment. Just trying to start a discussion... what do you do in your apps to deal with this? Is there a convention I'm missing?
* Revert "Simplify code in AS json encoder"Guillermo Iguaran2013-02-251-8/+15
| | | | | | This reverts commit 046e27a7338f2961c10e9d133e0e2229b51c2ba8. Check https://github.com/rails/rails/pull/8815#issuecomment-14026122 for details.
* Merge pull request #8815 from bogdan/simplified-to-json-argsSteve Klabnik2013-02-241-15/+8
|\ | | | | AS JSON encoder: remove monkey patch of Array
| * Simplify code in AS json encoderBogdan Gusiev2013-01-061-15/+8
| |
* | prefer american spelling of 'behavior'Gosha Arinich2013-01-071-1/+1
|/
* Remove unicode character encoding from ActiveSupport::JSON.encodeBrett Carter2012-12-141-7/+1
| | | | | | | | | | The encoding scheme (e.g. ☠ -> "\u2620") was broken for characters not in the Basic Multilingual Plane. It is possible to escape them for json using the weird encoding scheme of a twelve-character sequence representing the UTF-16 surrogate pair (e.g. '𠜎' -> "\u270e\u263a") but this wasn't properly handled in the escaping code. Since raw UTF-8 is allowed in json, it was decided to simply pass through the raw bytes rather than attempt to escape them.
* `#as_json` isolates options when encoding a hash. Closes #8182Yves Senn2012-11-121-1/+1
| | | | | | Setting options in a custom `#as_json` method had side effects. Modifications of the `options` hash leaked outside and influenced the conversion of other objects contained in the hash.
* update AS/json docs [ci skip]Francesco Rodriguez2012-09-141-10/+16
|
* Add back missing requireRafael Mendonça França2012-08-071-0/+1
|
* fixing :nodoc:s in AS::JSON::EncodingFrancesco Rodriguez2012-07-211-15/+48
|
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2012-06-021-1/+1
|\
| * Fix typo [ci skip]Erich Menge2012-05-301-1/+1
| |
* | Merge pull request #6554 from erichmenge/remove-json-variablePiotr Sarnacki2012-05-301-1/+0
|\ \ | |/ |/| Remove deprecated ActiveSupport::JSON::Variable.
| * Remove deprecated ActiveSupport::JSON::Variable.Erich Menge2012-05-301-1/+0
| |
* | Merge branch 'master' of github.com:lifo/docrailsVijay Dev2012-05-301-1/+4
|\ \ | |/ |/|
| * add example to ActiveSupport::JSON.encode [ci skip]Francesco Rodriguez2012-05-281-1/+4
| |
* | True, False, and Nil should be represented in as_json as themselves.Erich Menge2012-05-291-9/+9
|/
* Since escape_html_entities_in_json was moved to 3-2-stable, make it true in ↵José Valim2012-05-141-1/+1
| | | | AS, closes #6287
* BigDecimal string wrapping in JSON serialization can now be opted-out, fixes ↵David FRANCOIS2012-05-021-1/+14
| | | | #6033
* JSON: encode BigDecimal NaN/Infinity as null.Sebi Burkhard2012-05-011-1/+3
|
* Merge pull request #2532 from ↵Piotr Sarnacki2012-04-301-0/+4
|\ | | | | | | | | hasclass/as_json__encode_infinite_and_nan_floats_as_null JSON: Encode infinite or NaN floats as `null` to generate valid JSON.
| * JSON: Encode infinite or NaN floats as null to generate valid JSON.Sebi Burkhard2011-08-151-0/+4
| |
* | Replaced OrderedHash usage with Ruby 1.9 HashUddhava2012-02-091-3/+1
| |
* | fixes in api docsVijay Dev2012-01-131-2/+2
| |
* | Remove Array.wrap calls in ActiveSupportRafael Mendonça França2012-01-061-3/+2
| |
* | use #to_s to convert Range to jsonSergey Nartimov2012-01-011-0/+4
| |
* | remove checks for encodings availabilitySergey Nartimov2011-12-251-5/+3
| |
* | Revert "Implement ArraySerializer and move old serialization API to a new ↵José Valim2011-11-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | namespace." This reverts commit 8896b4fdc8a543157cdf4dfc378607ebf6c10ab0. Conflicts: activemodel/lib/active_model.rb activemodel/lib/active_model/serializable.rb activemodel/lib/active_model/serializer.rb activemodel/test/cases/serializer_test.rb
* | Implement ArraySerializer and move old serialization API to a new namespace.José Valim2011-11-231-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | The following constants were renamed: ActiveModel::Serialization => ActiveModel::Serializable ActiveModel::Serializers::JSON => ActiveModel::Serializable::JSON ActiveModel::Serializers::Xml => ActiveModel::Serializable::XML The main motivation for such a change is that `ActiveModel::Serializers::JSON` was not actually a serializer, but a module that when included allows the target to be serializable to JSON. With such changes, we were able to clean up the namespace to add true serializers as the ArraySerializer.
* | Set the default options value for as_json in the encoder object.José Valim2011-09-301-2/+2
|/
* Removed deprecated methods and related tests from ActiveSupportJosh Kalderimis2011-05-251-3/+0
|