multi_json 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +5 -3
- data/Gemfile +2 -1
- data/README.md +17 -22
- data/lib/multi_json.rb +2 -0
- data/lib/multi_json/engines/json_common.rb +10 -10
- data/lib/multi_json/engines/nsjsonserialization.rb +2 -2
- data/lib/multi_json/engines/oj.rb +22 -0
- data/lib/multi_json/engines/ok_json.rb +1 -1
- data/lib/multi_json/engines/yajl.rb +1 -1
- data/lib/multi_json/vendor/ok_json.rb +1 -1
- data/lib/multi_json/version.rb +1 -1
- data/multi_json.gemspec +1 -1
- data/spec/engine_shared_example.rb +115 -0
- data/spec/helper.rb +8 -14
- data/spec/multi_json_spec.rb +14 -127
- metadata +36 -13
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
gem 'json', '~> 1.4', :require => nil
|
4
|
-
gem '
|
4
|
+
gem 'oj', '~> 1.0', :require => nil, :platforms => [:ruby, :mswin, :mingw]
|
5
|
+
gem 'yajl-ruby', '~> 1.0', :require => nil, :platforms => [:ruby, :mswin, :mingw]
|
5
6
|
|
6
7
|
gemspec
|
data/README.md
CHANGED
@@ -3,42 +3,37 @@
|
|
3
3
|
[travis]: http://travis-ci.org/intridea/multi_json
|
4
4
|
[gemnasium]: https://gemnasium.com/intridea/multi_json
|
5
5
|
|
6
|
-
Lots of Ruby libraries
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
Lots of Ruby libraries parse JSON and everyone has their favorite JSON coder.
|
7
|
+
Instead of choosing a single JSON coder and forcing users of your library to be
|
8
|
+
stuck with it, you can use MultiJSON instead, which will simply choose the
|
9
|
+
fastest available JSON coder. Here's how to use it:
|
10
10
|
|
11
11
|
require 'multi_json'
|
12
12
|
|
13
|
-
MultiJson.
|
14
|
-
MultiJson.decode('{
|
15
|
-
|
16
|
-
MultiJson.
|
17
|
-
|
18
|
-
MultiJson.engine = :json_gem
|
19
|
-
MultiJson.engine = MultiJson::Engines::JsonGem # equivalent to previous line
|
20
|
-
MultiJson.encode({ :abc => 'def' }) # encoded using the JSON gem
|
21
|
-
|
22
|
-
MultiJson.encode({ :abc => 'def' }, :pretty => true) # encoded in a pretty form (ignored if engine is ok_json)
|
13
|
+
MultiJson.decode('{"abc":"def"}') #=> {"abc" => "def"}
|
14
|
+
MultiJson.decode('{"abc":"def"}', :symbolize_keys => true) #=> {:abc => "def"}
|
15
|
+
MultiJson.encode({:abc => 'def'}) # convert Ruby back to JSON
|
16
|
+
MultiJson.encode({:abc => 'def'}, :pretty => true) # encoded in a pretty form (if supported by the coder)
|
23
17
|
|
24
18
|
The `engine` setter takes either a symbol or a class (to allow for custom JSON
|
25
19
|
parsers) that responds to both `.decode` and `.encode` at the class level.
|
26
20
|
|
27
21
|
MultiJSON tries to have intelligent defaulting. That is, if you have any of the
|
28
22
|
supported engines already loaded, it will utilize them before attempting to
|
29
|
-
load any. When loading, libraries are ordered by speed. First
|
30
|
-
the JSON gem, then JSON pure. If no JSON library is available,
|
31
|
-
back to a
|
23
|
+
load any. When loading, libraries are ordered by speed. First Oj, then Yajl,
|
24
|
+
then the JSON gem, then JSON pure. If no other JSON library is available,
|
25
|
+
MultiJSON falls back to [OkJson][], a simple, vendorable JSON parser.
|
32
26
|
|
33
27
|
[okjson]: https://github.com/kr/okjson
|
34
28
|
|
35
29
|
## Supported JSON Engines
|
36
30
|
|
37
|
-
* [
|
38
|
-
* [
|
39
|
-
* [
|
40
|
-
* [
|
41
|
-
* [
|
31
|
+
* [Oj](https://github.com/ohler55/oj) Optimized JSON by Peter Ohler
|
32
|
+
* [Yajl](https://github.com/brianmario/yajl-ruby) Yet Another JSON Library by Brian Lopez
|
33
|
+
* [JSON](https://github.com/flori/json) The default JSON gem with C-extensions (ships with Ruby 1.9)
|
34
|
+
* [JSON Pure](https://github.com/flori/json) A Ruby variant of the JSON gem
|
35
|
+
* [NSJSONSerialization](https://developer.apple.com/library/ios/#documentation/Foundation/Reference/NSJSONSerialization_Class/Reference/Reference.html) Wrapper for Apple's NSJSONSerialization in the Cocoa Framework (MacRuby only)
|
36
|
+
* [OkJson][okjson] A simple, vendorable JSON parser
|
42
37
|
|
43
38
|
## <a name="contributing"></a>Contributing
|
44
39
|
In the spirit of [free software][free-sw], **everyone** is encouraged to help
|
data/lib/multi_json.rb
CHANGED
@@ -20,6 +20,7 @@ module MultiJson
|
|
20
20
|
end
|
21
21
|
|
22
22
|
REQUIREMENT_MAP = [
|
23
|
+
["oj", :oj],
|
23
24
|
["yajl", :yajl],
|
24
25
|
["json", :json_gem],
|
25
26
|
["json/pure", :json_pure]
|
@@ -32,6 +33,7 @@ module MultiJson
|
|
32
33
|
# if any engines are already loaded, then checks
|
33
34
|
# to see which are installed if none are loaded.
|
34
35
|
def default_engine
|
36
|
+
return :oj if defined?(::Oj)
|
35
37
|
return :yajl if defined?(::Yajl)
|
36
38
|
return :json_gem if defined?(::JSON)
|
37
39
|
|
@@ -2,26 +2,26 @@ module MultiJson
|
|
2
2
|
module Engines
|
3
3
|
module JsonCommon
|
4
4
|
|
5
|
-
def decode(string, options
|
5
|
+
def decode(string, options={})
|
6
6
|
opts = {}
|
7
7
|
opts[:symbolize_names] = options[:symbolize_keys]
|
8
8
|
string = string.read if string.respond_to?(:read)
|
9
9
|
::JSON.parse(string, opts)
|
10
10
|
end
|
11
11
|
|
12
|
-
def encode(object, options
|
12
|
+
def encode(object, options={})
|
13
13
|
object.to_json(process_options(options))
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
protected
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
def process_options(options={})
|
19
|
+
return options if options.empty?
|
20
|
+
opts = {}
|
21
|
+
opts.merge!(JSON::PRETTY_STATE_PROTOTYPE.to_h) if options.delete(:pretty)
|
22
|
+
opts.merge! options
|
23
|
+
end
|
24
24
|
|
25
25
|
end
|
26
26
|
end
|
27
|
-
end
|
27
|
+
end
|
@@ -5,7 +5,7 @@ module MultiJson
|
|
5
5
|
module Engines
|
6
6
|
class Nsjsonserialization < MultiJson::Engines::OkJson
|
7
7
|
ParseError = ::MultiJson::OkJson::Error
|
8
|
-
|
8
|
+
|
9
9
|
def self.decode(string, options = {})
|
10
10
|
string = string.read if string.respond_to?(:read)
|
11
11
|
data = string.dataUsingEncoding(NSUTF8StringEncoding)
|
@@ -28,7 +28,7 @@ module MultiJson
|
|
28
28
|
super(object, options)
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'oj' unless defined?(::Oj)
|
2
|
+
|
3
|
+
::Oj.default_options = {:mode => :compat}
|
4
|
+
|
5
|
+
module MultiJson
|
6
|
+
module Engines
|
7
|
+
# Use the Oj library to encode/decode.
|
8
|
+
class Oj
|
9
|
+
ParseError = SyntaxError
|
10
|
+
|
11
|
+
def self.decode(string, options = {}) #:nodoc:
|
12
|
+
opts = {}
|
13
|
+
opts[:symbol_keys] = options[:symbolize_keys]
|
14
|
+
::Oj.load(string, opts)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.encode(object, options = {}) #:nodoc:
|
18
|
+
::Oj.dump(object, options)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/multi_json/version.rb
CHANGED
data/multi_json.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.add_development_dependency 'rspec', '~> 2.6'
|
8
8
|
gem.add_development_dependency 'simplecov', '~> 0.4'
|
9
9
|
gem.authors = ["Michael Bleigh", "Josh Kalderimis", "Erik Michaels-Ober"]
|
10
|
-
gem.description = %q{A gem to provide
|
10
|
+
gem.description = %q{A gem to provide easy switching between different JSON backends, including Oj, Yajl, the JSON gem (with C-extensions), the pure-Ruby JSON gem, and OkJson.}
|
11
11
|
gem.email = ['michael@intridea.com', 'josh.kalderimis@gmail.com', 'sferik@gmail.com']
|
12
12
|
gem.extra_rdoc_files = ['LICENSE.md', 'README.md']
|
13
13
|
gem.files = Dir['LICENSE.md', 'README.md', 'Rakefile', 'multi_json.gemspec', 'Gemfile', '.document', '.rspec', '.travis.yml' ,'spec/**/*', 'lib/**/*']
|
@@ -0,0 +1,115 @@
|
|
1
|
+
shared_examples_for "an engine" do |engine|
|
2
|
+
|
3
|
+
before do
|
4
|
+
begin
|
5
|
+
MultiJson.engine = engine
|
6
|
+
rescue LoadError
|
7
|
+
pending "Engine #{engine} couldn't be loaded (not installed?)"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '.encode' do
|
12
|
+
it 'writes decodable JSON' do
|
13
|
+
[
|
14
|
+
{'abc' => 'def'},
|
15
|
+
[1, 2, 3, "4"],
|
16
|
+
].each do |example|
|
17
|
+
MultiJson.decode(MultiJson.encode(example)).should == example
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'encodes symbol keys as strings' do
|
22
|
+
[
|
23
|
+
[
|
24
|
+
{:foo => {:bar => 'baz'}},
|
25
|
+
{'foo' => {'bar' => 'baz'}},
|
26
|
+
],
|
27
|
+
[
|
28
|
+
[{:foo => {:bar => 'baz'}}],
|
29
|
+
[{'foo' => {'bar' => 'baz'}}],
|
30
|
+
],
|
31
|
+
[
|
32
|
+
{:foo => [{:bar => 'baz'}]},
|
33
|
+
{'foo' => [{'bar' => 'baz'}]},
|
34
|
+
]
|
35
|
+
].each do |example, expected|
|
36
|
+
encoded_json = MultiJson.encode(example)
|
37
|
+
MultiJson.decode(encoded_json).should == expected
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'encodes rootless JSON' do
|
42
|
+
MultiJson.encode("random rootless string").should == "\"random rootless string\""
|
43
|
+
MultiJson.encode(123).should == "123"
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'passes options to the engine' do
|
47
|
+
MultiJson.engine.should_receive(:encode).with('foo', {:bar => :baz})
|
48
|
+
MultiJson.encode('foo', :bar => :baz)
|
49
|
+
end
|
50
|
+
|
51
|
+
if engine == 'json_gem' || engine == 'json_pure'
|
52
|
+
describe 'with :pretty option set to true' do
|
53
|
+
it 'passes default pretty options' do
|
54
|
+
object = 'foo'
|
55
|
+
object.should_receive(:to_json).with(JSON::PRETTY_STATE_PROTOTYPE.to_h)
|
56
|
+
MultiJson.encode(object,:pretty => true)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it "encodes custom objects which implement as_json" do
|
62
|
+
MultiJson.encode(TimeWithZone.new).should == "\"2005-02-01T15:15:10Z\""
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '.decode' do
|
67
|
+
it 'properly decodes valid JSON' do
|
68
|
+
MultiJson.decode('{"abc":"def"}').should == {'abc' => 'def'}
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'raises MultiJson::DecodeError on invalid JSON' do
|
72
|
+
lambda do
|
73
|
+
MultiJson.decode('{"abc"}')
|
74
|
+
end.should raise_error(MultiJson::DecodeError)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'raises MultiJson::DecodeError with data on invalid JSON' do
|
78
|
+
data = '{invalid}'
|
79
|
+
begin
|
80
|
+
MultiJson.decode(data)
|
81
|
+
rescue MultiJson::DecodeError => de
|
82
|
+
de.data.should == data
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'stringifys symbol keys when encoding' do
|
87
|
+
encoded_json = MultiJson.encode(:a => 1, :b => {:c => 2})
|
88
|
+
MultiJson.decode(encoded_json).should == {"a" => 1, "b" => {"c" => 2}}
|
89
|
+
end
|
90
|
+
|
91
|
+
it "properly decodes valid JSON in StringIOs" do
|
92
|
+
json = StringIO.new('{"abc":"def"}')
|
93
|
+
MultiJson.decode(json).should == {'abc' => 'def'}
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'allows for symbolization of keys' do
|
97
|
+
[
|
98
|
+
[
|
99
|
+
'{"abc":{"def":"hgi"}}',
|
100
|
+
{:abc => {:def => 'hgi'}},
|
101
|
+
],
|
102
|
+
[
|
103
|
+
'[{"abc":{"def":"hgi"}}]',
|
104
|
+
[{:abc => {:def => 'hgi'}}],
|
105
|
+
],
|
106
|
+
[
|
107
|
+
'{"abc":[{"def":"hgi"}]}',
|
108
|
+
{:abc => [{:def => 'hgi'}]},
|
109
|
+
],
|
110
|
+
].each do |example, expected|
|
111
|
+
MultiJson.decode(example, :symbolize_keys => true).should == expected
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
data/spec/helper.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
|
+
def jruby?
|
2
|
+
defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
|
3
|
+
end
|
4
|
+
|
1
5
|
def macruby?
|
2
6
|
defined?(RUBY_ENGINE) && RUBY_ENGINE == 'macruby'
|
3
7
|
end
|
4
8
|
|
5
|
-
|
6
|
-
|
9
|
+
unless ENV['CI'] || macruby?
|
10
|
+
require 'simplecov'
|
11
|
+
SimpleCov.start
|
12
|
+
end
|
7
13
|
require 'multi_json'
|
8
14
|
require 'rspec'
|
9
15
|
|
@@ -22,15 +28,3 @@ class TimeWithZone
|
|
22
28
|
"\"2005-02-01T15:15:10Z\""
|
23
29
|
end
|
24
30
|
end
|
25
|
-
|
26
|
-
def yajl_on_travis(engine)
|
27
|
-
ENV['TRAVIS'] && engine == 'yajl' && jruby?
|
28
|
-
end
|
29
|
-
|
30
|
-
def nsjsonserialization_on_other_than_macruby(engine)
|
31
|
-
engine == 'nsjsonserialization' && !macruby?
|
32
|
-
end
|
33
|
-
|
34
|
-
def jruby?
|
35
|
-
defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
|
36
|
-
end
|
data/spec/multi_json_spec.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'helper'
|
2
|
+
require 'engine_shared_example'
|
2
3
|
require 'stringio'
|
3
4
|
|
4
|
-
describe
|
5
|
+
describe 'MultiJson' do
|
5
6
|
context 'engines' do
|
6
7
|
before do
|
7
8
|
MultiJson.engine = nil
|
@@ -9,21 +10,24 @@ describe "MultiJson" do
|
|
9
10
|
context 'when no other json implementations are available' do
|
10
11
|
before do
|
11
12
|
@old_map = MultiJson::REQUIREMENT_MAP
|
12
|
-
@old_yajl = Object.const_get :Yajl if Object.const_defined?(:Yajl)
|
13
13
|
@old_json = Object.const_get :JSON if Object.const_defined?(:JSON)
|
14
|
+
@old_oj = Object.const_get :Oj if Object.const_defined?(:Oj)
|
15
|
+
@old_yajl = Object.const_get :Yajl if Object.const_defined?(:Yajl)
|
14
16
|
MultiJson::REQUIREMENT_MAP.each_with_index do |(library, engine), index|
|
15
17
|
MultiJson::REQUIREMENT_MAP[index] = ["foo/#{library}", engine]
|
16
18
|
end
|
17
|
-
Object.send :remove_const, :Yajl if @old_yajl
|
18
19
|
Object.send :remove_const, :JSON if @old_json
|
20
|
+
Object.send :remove_const, :Oj if @old_oj
|
21
|
+
Object.send :remove_const, :Yajl if @old_yajl
|
19
22
|
end
|
20
23
|
|
21
24
|
after do
|
22
25
|
@old_map.each_with_index do |(library, engine), index|
|
23
26
|
MultiJson::REQUIREMENT_MAP[index] = [library, engine]
|
24
27
|
end
|
25
|
-
Object.const_set :Yajl, @old_yajl if @old_yajl
|
26
28
|
Object.const_set :JSON, @old_json if @old_json
|
29
|
+
Object.const_set :Oj, @old_oj if @old_oj
|
30
|
+
Object.const_set :Yajl, @old_yajl if @old_yajl
|
27
31
|
end
|
28
32
|
|
29
33
|
it 'defaults to ok_json if no other json implementions are available' do
|
@@ -38,8 +42,8 @@ describe "MultiJson" do
|
|
38
42
|
|
39
43
|
it 'defaults to the best available gem' do
|
40
44
|
unless jruby?
|
41
|
-
require '
|
42
|
-
MultiJson.engine.name.should == 'MultiJson::Engines::
|
45
|
+
require 'oj'
|
46
|
+
MultiJson.engine.name.should == 'MultiJson::Engines::Oj'
|
43
47
|
else
|
44
48
|
require 'json'
|
45
49
|
MultiJson.engine.name.should == 'MultiJson::Engines::JsonGem'
|
@@ -57,129 +61,12 @@ describe "MultiJson" do
|
|
57
61
|
end
|
58
62
|
end
|
59
63
|
|
60
|
-
%w(json_gem json_pure ok_json yajl
|
61
|
-
if
|
62
|
-
|
63
|
-
next
|
64
|
-
end
|
65
|
-
if nsjsonserialization_on_other_than_macruby(engine)
|
66
|
-
puts "NSJSONSerialization is exclusively available for MacRuby only."
|
67
|
-
next
|
68
|
-
end
|
64
|
+
%w(json_gem json_pure nsjsonserialization oj ok_json yajl).each do |engine|
|
65
|
+
next if !macruby? && engine == 'nsjsonserialization'
|
66
|
+
next if jruby? && (engine == 'oj' || engine == 'yajl')
|
69
67
|
|
70
68
|
context engine do
|
71
|
-
|
72
|
-
begin
|
73
|
-
MultiJson.engine = engine
|
74
|
-
rescue LoadError
|
75
|
-
pending "Engine #{engine} couldn't be loaded (not installed?)"
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe '.encode' do
|
80
|
-
it 'writes decodable JSON' do
|
81
|
-
[
|
82
|
-
{ 'abc' => 'def' },
|
83
|
-
[1, 2, 3, "4"]
|
84
|
-
].each do |example|
|
85
|
-
MultiJson.decode(MultiJson.encode(example)).should == example
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'encodes symbol keys as strings' do
|
90
|
-
[
|
91
|
-
[
|
92
|
-
{ :foo => { :bar => 'baz' } },
|
93
|
-
{ 'foo' => { 'bar' => 'baz' } }
|
94
|
-
],
|
95
|
-
[
|
96
|
-
[ { :foo => { :bar => 'baz' } } ],
|
97
|
-
[ { 'foo' => { 'bar' => 'baz' } } ],
|
98
|
-
],
|
99
|
-
[
|
100
|
-
{ :foo => [ { :bar => 'baz' } ] },
|
101
|
-
{ 'foo' => [ { 'bar' => 'baz' } ] },
|
102
|
-
]
|
103
|
-
].each do |example, expected|
|
104
|
-
encoded_json = MultiJson.encode(example)
|
105
|
-
MultiJson.decode(encoded_json).should == expected
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'encodes rootless JSON' do
|
110
|
-
MultiJson.encode("random rootless string").should == "\"random rootless string\""
|
111
|
-
MultiJson.encode(123).should == "123"
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'passes options to the engine' do
|
115
|
-
MultiJson.engine.should_receive(:encode).with('foo', {:bar => :baz})
|
116
|
-
MultiJson.encode('foo', :bar => :baz)
|
117
|
-
end
|
118
|
-
|
119
|
-
if engine == 'json_gem' || engine == 'json_pure'
|
120
|
-
describe 'with :pretty option set to true' do
|
121
|
-
it 'passes default pretty options' do
|
122
|
-
object = 'foo'
|
123
|
-
object.should_receive(:to_json).with(JSON::PRETTY_STATE_PROTOTYPE.to_h)
|
124
|
-
MultiJson.encode(object,:pretty => true)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
it "encodes custom objects which implement as_json" do
|
130
|
-
MultiJson.encode(TimeWithZone.new).should == "\"2005-02-01T15:15:10Z\""
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
describe '.decode' do
|
135
|
-
it 'properly decodes valid JSON' do
|
136
|
-
MultiJson.decode('{"abc":"def"}').should == { 'abc' => 'def' }
|
137
|
-
end
|
138
|
-
|
139
|
-
it 'raises MultiJson::DecodeError on invalid JSON' do
|
140
|
-
lambda do
|
141
|
-
MultiJson.decode('{"abc"}')
|
142
|
-
end.should raise_error(MultiJson::DecodeError)
|
143
|
-
end
|
144
|
-
|
145
|
-
it 'raises MultiJson::DecodeError with data on invalid JSON' do
|
146
|
-
data = '{invalid}'
|
147
|
-
begin
|
148
|
-
MultiJson.decode(data)
|
149
|
-
rescue MultiJson::DecodeError => de
|
150
|
-
de.data.should == data
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
it 'stringifys symbol keys when encoding' do
|
155
|
-
encoded_json = MultiJson.encode(:a => 1, :b => {:c => 2})
|
156
|
-
MultiJson.decode(encoded_json).should == { "a" => 1, "b" => { "c" => 2 } }
|
157
|
-
end
|
158
|
-
|
159
|
-
it "properly decodes valid JSON in StringIOs" do
|
160
|
-
json = StringIO.new('{"abc":"def"}')
|
161
|
-
MultiJson.decode(json).should == { 'abc' => 'def' }
|
162
|
-
end
|
163
|
-
|
164
|
-
it 'allows for symbolization of keys' do
|
165
|
-
[
|
166
|
-
[
|
167
|
-
'{"abc":{"def":"hgi"}}',
|
168
|
-
{ :abc => { :def => 'hgi' } }
|
169
|
-
],
|
170
|
-
[
|
171
|
-
'[{"abc":{"def":"hgi"}}]',
|
172
|
-
[ { :abc => { :def => 'hgi' } } ]
|
173
|
-
],
|
174
|
-
[
|
175
|
-
'{"abc":[{"def":"hgi"}]}',
|
176
|
-
{ :abc => [ { :def => 'hgi' } ] }
|
177
|
-
],
|
178
|
-
].each do |example, expected|
|
179
|
-
MultiJson.decode(example, :symbolize_keys => true).should == expected
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
69
|
+
it_should_behave_like "an engine", engine
|
183
70
|
end
|
184
71
|
end
|
185
72
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multi_json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,11 +11,11 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-
|
14
|
+
date: 2012-03-27 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rake
|
18
|
-
requirement:
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ~>
|
@@ -23,10 +23,15 @@ dependencies:
|
|
23
23
|
version: '0.9'
|
24
24
|
type: :development
|
25
25
|
prerelease: false
|
26
|
-
version_requirements:
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ~>
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '0.9'
|
27
32
|
- !ruby/object:Gem::Dependency
|
28
33
|
name: rdoc
|
29
|
-
requirement:
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
30
35
|
none: false
|
31
36
|
requirements:
|
32
37
|
- - ~>
|
@@ -34,10 +39,15 @@ dependencies:
|
|
34
39
|
version: '3.9'
|
35
40
|
type: :development
|
36
41
|
prerelease: false
|
37
|
-
version_requirements:
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.9'
|
38
48
|
- !ruby/object:Gem::Dependency
|
39
49
|
name: rspec
|
40
|
-
requirement:
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
41
51
|
none: false
|
42
52
|
requirements:
|
43
53
|
- - ~>
|
@@ -45,10 +55,15 @@ dependencies:
|
|
45
55
|
version: '2.6'
|
46
56
|
type: :development
|
47
57
|
prerelease: false
|
48
|
-
version_requirements:
|
58
|
+
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ~>
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '2.6'
|
49
64
|
- !ruby/object:Gem::Dependency
|
50
65
|
name: simplecov
|
51
|
-
requirement:
|
66
|
+
requirement: !ruby/object:Gem::Requirement
|
52
67
|
none: false
|
53
68
|
requirements:
|
54
69
|
- - ~>
|
@@ -56,9 +71,14 @@ dependencies:
|
|
56
71
|
version: '0.4'
|
57
72
|
type: :development
|
58
73
|
prerelease: false
|
59
|
-
version_requirements:
|
60
|
-
|
61
|
-
|
74
|
+
version_requirements: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ~>
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0.4'
|
80
|
+
description: A gem to provide easy switching between different JSON backends, including
|
81
|
+
Oj, Yajl, the JSON gem (with C-extensions), the pure-Ruby JSON gem, and OkJson.
|
62
82
|
email:
|
63
83
|
- michael@intridea.com
|
64
84
|
- josh.kalderimis@gmail.com
|
@@ -77,12 +97,14 @@ files:
|
|
77
97
|
- .document
|
78
98
|
- .rspec
|
79
99
|
- .travis.yml
|
100
|
+
- spec/engine_shared_example.rb
|
80
101
|
- spec/helper.rb
|
81
102
|
- spec/multi_json_spec.rb
|
82
103
|
- lib/multi_json/engines/json_common.rb
|
83
104
|
- lib/multi_json/engines/json_gem.rb
|
84
105
|
- lib/multi_json/engines/json_pure.rb
|
85
106
|
- lib/multi_json/engines/nsjsonserialization.rb
|
107
|
+
- lib/multi_json/engines/oj.rb
|
86
108
|
- lib/multi_json/engines/ok_json.rb
|
87
109
|
- lib/multi_json/engines/yajl.rb
|
88
110
|
- lib/multi_json/vendor/ok_json.rb
|
@@ -109,11 +131,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
131
|
version: 1.3.6
|
110
132
|
requirements: []
|
111
133
|
rubyforge_project:
|
112
|
-
rubygems_version: 1.8.
|
134
|
+
rubygems_version: 1.8.21
|
113
135
|
signing_key:
|
114
136
|
specification_version: 3
|
115
137
|
summary: A gem to provide swappable JSON backends.
|
116
138
|
test_files:
|
139
|
+
- spec/engine_shared_example.rb
|
117
140
|
- spec/helper.rb
|
118
141
|
- spec/multi_json_spec.rb
|
119
142
|
has_rdoc:
|