From 0bc3d4936be6d173ea7dbb535360ff588bd3ad11 Mon Sep 17 00:00:00 2001 From: Bob Aman Date: Thu, 5 Jan 2012 13:05:56 +0300 Subject: [PATCH] Migrated to MultiJson from JSON gem. --- lib/google/api_client.rb | 8 ++++---- lib/google/api_client/discovery/schema.rb | 2 +- lib/google/api_client/parser.rb | 2 +- lib/google/api_client/parsers/json_parser.rb | 6 +++--- lib/google/api_client/reference.rb | 4 ++-- lib/google/api_client/result.rb | 2 +- spec/google/api_client/discovery_spec.rb | 4 ++-- spec/google/api_client/parsers/json_parser_spec.rb | 2 +- tasks/gem.rake | 2 +- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/google/api_client.rb b/lib/google/api_client.rb index f01a8d93e..a1074020a 100644 --- a/lib/google/api_client.rb +++ b/lib/google/api_client.rb @@ -14,7 +14,7 @@ require 'httpadapter' -require 'json' +require 'multi_json' require 'stringio' require 'google/api_client/version' @@ -268,7 +268,7 @@ module Google "Expected String or StringIO, got #{discovery_document.class}." end @discovery_documents["#{api}:#{version}"] = - ::JSON.parse(discovery_document) + MultiJson.decode(discovery_document) end ## @@ -290,7 +290,7 @@ module Google accu.write(chunk) accu end - ::JSON.parse(merged_body.string) + MultiJson.decode(merged_body.string) elsif status >= 400 && status < 500 _, request_uri, _, _ = request raise ClientError, @@ -330,7 +330,7 @@ module Google accu.write(chunk) accu end - ::JSON.parse(merged_body.string) + MultiJson.decode(merged_body.string) elsif status >= 400 && status < 500 _, request_uri, _, _ = request raise ClientError, diff --git a/lib/google/api_client/discovery/schema.rb b/lib/google/api_client/discovery/schema.rb index 9421be1e1..ba8195070 100644 --- a/lib/google/api_client/discovery/schema.rb +++ b/lib/google/api_client/discovery/schema.rb @@ -14,7 +14,7 @@ require 'time' -require 'json' +require 'multi_json' require 'base64' require 'autoparse' require 'addressable/uri' diff --git a/lib/google/api_client/parser.rb b/lib/google/api_client/parser.rb index c8cb5365d..84b5918d0 100644 --- a/lib/google/api_client/parser.rb +++ b/lib/google/api_client/parser.rb @@ -13,7 +13,7 @@ # limitations under the License. -require 'json' +require 'multi_json' module Google diff --git a/lib/google/api_client/parsers/json_parser.rb b/lib/google/api_client/parsers/json_parser.rb index b7c366ac7..56b6c7663 100644 --- a/lib/google/api_client/parsers/json_parser.rb +++ b/lib/google/api_client/parsers/json_parser.rb @@ -13,7 +13,7 @@ # limitations under the License. -require 'json' +require 'multi_json' require 'google/api_client/parser' @@ -55,7 +55,7 @@ module Google end def initialize(data) - @data = data.kind_of?(Hash) ? data : ::JSON.parse(data) + @data = data.kind_of?(Hash) ? data : MultiJson.decode(data) end def [](key) @@ -107,7 +107,7 @@ module Google end def self.parse(json) - data = json.kind_of?(Hash) ? json : ::JSON.parse(json) + data = json.kind_of?(Hash) ? json : MultiJson.decode(json) parser = self.match(data) if parser return parser.new(data) diff --git a/lib/google/api_client/reference.rb b/lib/google/api_client/reference.rb index 0a24b0c59..936ae60d4 100644 --- a/lib/google/api_client/reference.rb +++ b/lib/google/api_client/reference.rb @@ -14,7 +14,7 @@ require 'stringio' -require 'json' +require 'multi_json' require 'addressable/uri' require 'google/api_client/discovery' @@ -44,7 +44,7 @@ module Google if options[:body_object].respond_to?(:to_json) serialized_body = options[:body_object].to_json elsif options[:body_object].respond_to?(:to_hash) - serialized_body = JSON.generate(options[:body_object].to_hash) + serialized_body = MultiJson.encode(options[:body_object].to_hash) else raise TypeError, 'Could not convert body object to JSON.' + diff --git a/lib/google/api_client/result.rb b/lib/google/api_client/result.rb index 0abc1ac67..65bac1575 100644 --- a/lib/google/api_client/result.rb +++ b/lib/google/api_client/result.rb @@ -57,7 +57,7 @@ module Google data = self.body case media_type when 'application/json' - data = ::JSON.parse(data) + data = MultiJson.decode(data) # Strip data wrapper, if present data = data['data'] if data.has_key?('data') else diff --git a/spec/google/api_client/discovery_spec.rb b/spec/google/api_client/discovery_spec.rb index 6d0711abe..1d5cc22d0 100644 --- a/spec/google/api_client/discovery_spec.rb +++ b/spec/google/api_client/discovery_spec.rb @@ -14,7 +14,7 @@ require 'spec_helper' -require 'json' +require 'multi_json' require 'signet/oauth_1/client' require 'httpadapter/adapters/net_http' @@ -298,7 +298,7 @@ describe Google::APIClient do result = @client.execute( @prediction.training.insert, {}, - JSON.generate({"id" => "bucket/object"}), + MultiJson.encode({"id" => "bucket/object"}), {'Content-Type' => 'application/json'} ) method, uri, headers, body = result.request diff --git a/spec/google/api_client/parsers/json_parser_spec.rb b/spec/google/api_client/parsers/json_parser_spec.rb index c7361ccf6..e04d71cdb 100644 --- a/spec/google/api_client/parsers/json_parser_spec.rb +++ b/spec/google/api_client/parsers/json_parser_spec.rb @@ -14,7 +14,7 @@ require 'spec_helper' -require 'json' +require 'multi_json' require 'google/api_client/parsers/json_parser' require 'google/api_client/parsers/json/error_parser' require 'google/api_client/parsers/json/pagination' diff --git a/tasks/gem.rake b/tasks/gem.rake index 766df88c8..0c47cb95d 100644 --- a/tasks/gem.rake +++ b/tasks/gem.rake @@ -28,7 +28,7 @@ namespace :gem do s.add_runtime_dependency('addressable', '~> 2.2.2') s.add_runtime_dependency('httpadapter', '~> 1.0.1') s.add_runtime_dependency('autoparse', '~> 0.2.0') - s.add_runtime_dependency('json', '>= 1.4.6') + s.add_runtime_dependency('multi_json', '>= 1.0.0') s.add_runtime_dependency('extlib', '>= 0.9.15') # Dependencies used in the CLI