json_format.rb 475 B

123456789101112131415161718
  1. module ActiveResource
  2. # ActiveResource 3.1 removes root on decoding, so this patch is only needed in 3.0
  3. if ActiveResource::VERSION::MAJOR == 3 && ActiveResource::VERSION::MINOR == 0
  4. module Formats
  5. module JsonFormat
  6. def decode(json)
  7. data = ActiveSupport::JSON.decode(json)
  8. if data.is_a?(Hash) && data.keys.size == 1
  9. data.values.first
  10. else
  11. data
  12. end
  13. end
  14. end
  15. end
  16. end
  17. end