diff options
-rw-r--r-- | activesupport/lib/active_support/core_ext/object/json.rb | 7 | ||||
-rw-r--r-- | activesupport/test/json/encoding_test_cases.rb | 2 |
2 files changed, 9 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/object/json.rb b/activesupport/lib/active_support/core_ext/object/json.rb index 32a41eafe4..363bde5a68 100644 --- a/activesupport/lib/active_support/core_ext/object/json.rb +++ b/activesupport/lib/active_support/core_ext/object/json.rb @@ -2,6 +2,7 @@ require 'json' require 'bigdecimal' require 'uri/generic' +require 'pathname' require 'active_support/core_ext/big_decimal/conversions' # for #to_s require 'active_support/core_ext/hash/except' require 'active_support/core_ext/hash/slice' @@ -199,6 +200,12 @@ class URI::Generic #:nodoc: end end +class Pathname #:nodoc: + def as_json(options = nil) + to_s + end +end + class Process::Status #:nodoc: def as_json(options = nil) { :exitstatus => exitstatus, :pid => pid } diff --git a/activesupport/test/json/encoding_test_cases.rb b/activesupport/test/json/encoding_test_cases.rb index 60d8685d32..e043fadf56 100644 --- a/activesupport/test/json/encoding_test_cases.rb +++ b/activesupport/test/json/encoding_test_cases.rb @@ -78,6 +78,8 @@ module JSONTest URITests = [[ URI.parse('http://example.com'), %("http://example.com") ]] + PathnameTests = [[ Pathname.new('lib/index.rb'), %("lib/index.rb") ]] + DateTests = [[ Date.new(2005,2,1), %("2005/02/01") ]] TimeTests = [[ Time.utc(2005,2,1,15,15,10), %("2005/02/01 15:15:10 +0000") ]] DateTimeTests = [[ DateTime.civil(2005,2,1,15,15,10), %("2005/02/01 15:15:10 +0000") ]] |