aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/json
diff options
context:
space:
mode:
authorErich Menge <erich.menge@me.com>2012-05-29 16:40:43 -0500
committerErich Menge <erich.menge@me.com>2012-05-29 21:13:03 -0500
commit1e335ad1380f85e016260a8a3e38013376e1c109 (patch)
tree0fc5d6e806f71a504811f3338dbfba8b5ddb9239 /activesupport/lib/active_support/json
parent669694fe888053ccc86e9a9d1d19adb8dba5fafb (diff)
downloadrails-1e335ad1380f85e016260a8a3e38013376e1c109.tar.gz
rails-1e335ad1380f85e016260a8a3e38013376e1c109.tar.bz2
rails-1e335ad1380f85e016260a8a3e38013376e1c109.zip
True, False, and Nil should be represented in as_json as themselves.
Diffstat (limited to 'activesupport/lib/active_support/json')
-rw-r--r--activesupport/lib/active_support/json/encoding.rb18
1 files changed, 9 insertions, 9 deletions
diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb
index a6e4e7ced2..41fe61e790 100644
--- a/activesupport/lib/active_support/json/encoding.rb
+++ b/activesupport/lib/active_support/json/encoding.rb
@@ -159,18 +159,18 @@ class Struct #:nodoc:
end
class TrueClass
- AS_JSON = ActiveSupport::JSON::Variable.new('true').freeze
- def as_json(options = nil) AS_JSON end #:nodoc:
+ def as_json(options = nil) self end #:nodoc:
+ def encode_json(encoder) to_s end #:nodoc:
end
class FalseClass
- AS_JSON = ActiveSupport::JSON::Variable.new('false').freeze
- def as_json(options = nil) AS_JSON end #:nodoc:
+ def as_json(options = nil) self end #:nodoc:
+ def encode_json(encoder) to_s end #:nodoc:
end
class NilClass
- AS_JSON = ActiveSupport::JSON::Variable.new('null').freeze
- def as_json(options = nil) AS_JSON end #:nodoc:
+ def as_json(options = nil) self end #:nodoc:
+ def encode_json(encoder) 'null' end #:nodoc:
end
class String
@@ -189,8 +189,8 @@ end
class Float
# Encoding Infinity or NaN to JSON should return "null". The default returns
- # "Infinity" or "NaN" what breaks parsing the JSON. E.g. JSON.parse('[NaN]').
- def as_json(options = nil) finite? ? self : NilClass::AS_JSON end #:nodoc:
+ # "Infinity" or "NaN" breaks parsing the JSON. E.g. JSON.parse('[NaN]').
+ def as_json(options = nil) finite? ? self : nil end #:nodoc:
end
class BigDecimal
@@ -208,7 +208,7 @@ class BigDecimal
if finite?
ActiveSupport.encode_big_decimal_as_string ? to_s : self
else
- NilClass::AS_JSON
+ nil
end
end
end