aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/json/backends/yaml.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/json/backends/yaml.rb')
-rw-r--r--activesupport/lib/active_support/json/backends/yaml.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/json/backends/yaml.rb b/activesupport/lib/active_support/json/backends/yaml.rb
index c7db508c23..667016f45d 100644
--- a/activesupport/lib/active_support/json/backends/yaml.rb
+++ b/activesupport/lib/active_support/json/backends/yaml.rb
@@ -2,15 +2,20 @@ require 'active_support/core_ext/string/starts_ends_with'
module ActiveSupport
module JSON
- class ParseError < StandardError
+ unless const_defined?(:ParseError)
+ class ParseError < StandardError
+ end
end
module Backends
module Yaml
extend self
- # Converts a JSON string into a Ruby object.
+ # Parses a JSON string or IO and converts it into an object
def decode(json)
+ if json.respond_to?(:read)
+ json = json.read
+ end
YAML.load(convert_json_to_yaml(json))
rescue ArgumentError => e
raise ParseError, "Invalid JSON string"