multi_json 1.8.4 → 1.9.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.travis.yml +2 -7
- data/CHANGELOG.md +5 -0
- data/Gemfile +0 -4
- data/README.md +19 -6
- data/lib/multi_json.rb +6 -5
- data/lib/multi_json/adapter_error.rb +15 -0
- data/lib/multi_json/parse_error.rb +17 -0
- data/lib/multi_json/version.rb +2 -2
- data/spec/multi_json_spec.rb +9 -2
- data/spec/shared/adapter.rb +17 -13
- data/spec/spec_helper.rb +9 -1
- metadata +19 -15
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9310cbdab77060e6ad1605d2f6db0ea00f1b5204
|
4
|
+
data.tar.gz: 7bc409de5e81b71bce457fe2f33b962ea2d3ab96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5243b47e82a2f5f5bcc0d45a7b76ea8fdc63585b092d4acc05bfcc10fc35ebd4823a552a730e7ed112a702dc4a0e1b4de757fb23c397258ed1919fa6d1de4418
|
7
|
+
data.tar.gz: f4d223b885d5efa05873ffb3be1f862b130e591c838269b4651243e0661d0c40c6b59b41b682d33fea00fc50dc1e9aacf6bc80326992401432e5d97d02c80a1d
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/.travis.yml
CHANGED
@@ -1,8 +1,3 @@
|
|
1
|
-
before_install:
|
2
|
-
- gem update bundler
|
3
|
-
- bundle --version
|
4
|
-
- gem update --system 2.1.11
|
5
|
-
- gem --version
|
6
1
|
bundler_args: --without development
|
7
2
|
language: ruby
|
8
3
|
rvm:
|
@@ -11,14 +6,14 @@ rvm:
|
|
11
6
|
- 1.9.3
|
12
7
|
- 2.0.0
|
13
8
|
- 2.1.0
|
9
|
+
- 2.1.1
|
14
10
|
- jruby-18mode
|
15
11
|
- jruby-19mode
|
16
12
|
- jruby-head
|
17
|
-
- rbx
|
13
|
+
- rbx-2
|
18
14
|
- ruby-head
|
19
15
|
matrix:
|
20
16
|
allow_failures:
|
21
17
|
- rvm: jruby-head
|
22
|
-
- rvm: rbx
|
23
18
|
- rvm: ruby-head
|
24
19
|
fast_finish: true
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
1.9.0
|
2
|
+
----
|
3
|
+
* [Rename LoadError to ParseError](https://github.com/intridea/multi_json/commit/4abb98fe3a90b2a7b3d1594515c8a06042b4a27d)
|
4
|
+
* [Adapter load failure throws AdapterError instead of ArgumentError](https://github.com/intridea/multi_json/commit/4da612b617bd932bb6fa1cc4c43210327f98f271)
|
5
|
+
|
1
6
|
1.8.4
|
2
7
|
-----
|
3
8
|
* [Make Gson adapter explicitly read StringIO object](https://github.com/intridea/multi_json/commit/b58b498747ff6e94f41488c971b2a30a98760ef2)
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
# MultiJSON
|
2
2
|
|
3
|
-
[][gem]
|
4
|
+
[][travis]
|
5
|
+
[][gemnasium]
|
6
|
+
[][codeclimate]
|
7
7
|
|
8
8
|
[gem]: https://rubygems.org/gems/multi_json
|
9
9
|
[travis]: http://travis-ci.org/intridea/multi_json
|
10
10
|
[gemnasium]: https://gemnasium.com/intridea/multi_json
|
11
11
|
[codeclimate]: https://codeclimate.com/github/intridea/multi_json
|
12
|
+
|
12
13
|
Lots of Ruby libraries parse JSON and everyone has their favorite JSON coder.
|
13
14
|
Instead of choosing a single JSON coder and forcing users of your library to be
|
14
15
|
stuck with it, you can use MultiJSON instead, which will simply choose the
|
@@ -23,16 +24,27 @@ MultiJson.dump({:abc => 'def'}) # convert Ruby back to JSON
|
|
23
24
|
MultiJson.dump({:abc => 'def'}, :pretty => true) # encoded in a pretty form (if supported by the coder)
|
24
25
|
```
|
25
26
|
|
26
|
-
When loading invalid JSON,
|
27
|
+
When loading invalid JSON, MultiJson will throw a `MultiJson::ParseError`. `MultiJson::DecodeError` and `MultiJson::LoadError` are aliases for backwards compatibility.
|
27
28
|
|
28
29
|
```ruby
|
29
|
-
|
30
|
+
begin
|
31
|
+
MultiJson.load('{invalid json}')
|
32
|
+
rescue MultiJson::ParseError => exception
|
33
|
+
exception.data # => "{invalid json}"
|
34
|
+
exception.cause # => JSON::ParserError: 795: unexpected token at '{invalid json}'
|
35
|
+
end
|
30
36
|
```
|
31
37
|
|
38
|
+
`ParseError` instance has `cause` reader which contains the original exception.
|
39
|
+
It also has `data` reader with the input that caused the problem.
|
40
|
+
|
32
41
|
The `use` method, which sets the MultiJson adapter, takes either a symbol or a
|
33
42
|
class (to allow for custom JSON parsers) that responds to both `.load` and `.dump`
|
34
43
|
at the class level.
|
35
44
|
|
45
|
+
When MultiJson fails to load the specified adapter, it'll throw `MultiJson::AdapterError`
|
46
|
+
which inherits from `ArgumentError`.
|
47
|
+
|
36
48
|
MultiJSON tries to have intelligent defaulting. That is, if you have any of the
|
37
49
|
supported engines already loaded, it will utilize them before attempting to
|
38
50
|
load any. When loading, libraries are ordered by speed. First Oj, then Yajl,
|
@@ -61,6 +73,7 @@ implementations:
|
|
61
73
|
* Ruby 1.9.3
|
62
74
|
* Ruby 2.0.0
|
63
75
|
* Ruby 2.1.0
|
76
|
+
* Ruby 2.1.1
|
64
77
|
* [JRuby][]
|
65
78
|
* [Rubinius][]
|
66
79
|
* [MacRuby][] (not tested on Travis CI)
|
data/lib/multi_json.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'multi_json/options'
|
2
2
|
require 'multi_json/version'
|
3
|
-
require 'multi_json/
|
3
|
+
require 'multi_json/adapter_error'
|
4
|
+
require 'multi_json/parse_error'
|
4
5
|
|
5
6
|
module MultiJson
|
6
7
|
include Options
|
@@ -102,10 +103,10 @@ module MultiJson
|
|
102
103
|
when Class, Module
|
103
104
|
new_adapter
|
104
105
|
else
|
105
|
-
raise ::LoadError
|
106
|
+
raise ::LoadError, new_adapter
|
106
107
|
end
|
107
|
-
rescue ::LoadError
|
108
|
-
raise
|
108
|
+
rescue ::LoadError => exception
|
109
|
+
raise AdapterError.build(exception)
|
109
110
|
end
|
110
111
|
|
111
112
|
# Decode a JSON string into Ruby.
|
@@ -119,7 +120,7 @@ module MultiJson
|
|
119
120
|
begin
|
120
121
|
adapter.load(string, options)
|
121
122
|
rescue adapter::ParseError => exception
|
122
|
-
raise
|
123
|
+
raise ParseError.build(exception, string)
|
123
124
|
end
|
124
125
|
end
|
125
126
|
alias decode load
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module MultiJson
|
2
|
+
class AdapterError < ArgumentError
|
3
|
+
attr_reader :cause
|
4
|
+
|
5
|
+
def self.build(original_exception)
|
6
|
+
message = "Did not recognize your adapter specification (#{original_exception.message})."
|
7
|
+
new(message).tap do |exception|
|
8
|
+
exception.instance_eval do
|
9
|
+
@cause = original_exception
|
10
|
+
set_backtrace original_exception.backtrace
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module MultiJson
|
2
|
+
class ParseError < StandardError
|
3
|
+
attr_reader :data, :cause
|
4
|
+
|
5
|
+
def self.build(original_exception, data)
|
6
|
+
new(original_exception.message).tap do |exception|
|
7
|
+
exception.instance_eval do
|
8
|
+
@cause = original_exception
|
9
|
+
set_backtrace original_exception.backtrace
|
10
|
+
@data = data
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
DecodeError = LoadError = ParseError # Legacy support
|
17
|
+
end
|
data/lib/multi_json/version.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module MultiJson
|
2
2
|
class Version
|
3
3
|
MAJOR = 1 unless defined? MultiJson::Version::MAJOR
|
4
|
-
MINOR =
|
5
|
-
PATCH =
|
4
|
+
MINOR = 9 unless defined? MultiJson::Version::MINOR
|
5
|
+
PATCH = 0 unless defined? MultiJson::Version::PATCH
|
6
6
|
PRE = nil unless defined? MultiJson::Version::PRE
|
7
7
|
|
8
8
|
class << self
|
data/spec/multi_json_spec.rb
CHANGED
@@ -89,8 +89,15 @@ describe MultiJson do
|
|
89
89
|
expect(MultiJson.adapter).to eq(adapter)
|
90
90
|
end
|
91
91
|
|
92
|
-
it 'throws
|
93
|
-
expect{ MultiJson.use 'bad adapter' }.to raise_error(
|
92
|
+
it 'throws AdapterError on bad input' do
|
93
|
+
expect{ MultiJson.use 'bad adapter' }.to raise_error(MultiJson::AdapterError, /bad adapter/)
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'gives access to original error when raising AdapterError' do
|
97
|
+
exception = get_exception(MultiJson::AdapterError){ MultiJson.use 'foobar' }
|
98
|
+
expect(exception.cause).to be_instance_of(::LoadError)
|
99
|
+
expect(exception.message).to include("-- multi_json/adapters/foobar")
|
100
|
+
expect(exception.message).to include("Did not recognize your adapter specification")
|
94
101
|
end
|
95
102
|
|
96
103
|
context 'using one-shot parser' do
|
data/spec/shared/adapter.rb
CHANGED
@@ -162,35 +162,39 @@ shared_examples_for 'an adapter' do |adapter|
|
|
162
162
|
expect(MultiJson.load('{"abc":"def"}')).to eq('abc' => 'def')
|
163
163
|
end
|
164
164
|
|
165
|
-
it 'raises MultiJson::
|
165
|
+
it 'raises MultiJson::ParseError on blank input or invalid input' do
|
166
166
|
[nil, '{"abc"}', ' ', "\t\t\t", "\n", "\x82\xAC\xEF"].each do |input|
|
167
167
|
if input == "\x82\xAC\xEF"
|
168
168
|
pending 'GSON bug: https://github.com/avsej/gson.rb/issues/3' if adapter.name =~ /Gson/
|
169
169
|
pending 'JrJackson bug: https://github.com/guyboertje/jrjackson/issues/21' if adapter.name =~ /JrJackson/
|
170
170
|
end
|
171
171
|
|
172
|
-
expect{MultiJson.load(input)}.to raise_error(MultiJson::
|
172
|
+
expect{MultiJson.load(input)}.to raise_error(MultiJson::ParseError)
|
173
173
|
end
|
174
174
|
end
|
175
175
|
|
176
|
-
it 'raises MultiJson::
|
176
|
+
it 'raises MultiJson::ParseError with data on invalid JSON' do
|
177
177
|
data = '{invalid}'
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
expect(le.data).to eq(data)
|
182
|
-
end
|
178
|
+
exception = get_exception(MultiJson::ParseError){ MultiJson.load data }
|
179
|
+
expect(exception.data).to eq(data)
|
180
|
+
expect(exception.cause).to be_kind_of(MultiJson.adapter::ParseError)
|
183
181
|
end
|
184
182
|
|
185
183
|
it 'catches MultiJson::DecodeError for legacy support' do
|
186
184
|
data = '{invalid}'
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
185
|
+
exception = get_exception(MultiJson::DecodeError){ MultiJson.load data }
|
186
|
+
expect(exception.data).to eq(data)
|
187
|
+
expect(exception.cause).to be_kind_of(MultiJson.adapter::ParseError)
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'catches MultiJson::LoadError for legacy support' do
|
191
|
+
data = '{invalid}'
|
192
|
+
exception = get_exception(MultiJson::LoadError){ MultiJson.load data }
|
193
|
+
expect(exception.data).to eq(data)
|
194
|
+
expect(exception.cause).to be_kind_of(MultiJson.adapter::ParseError)
|
192
195
|
end
|
193
196
|
|
197
|
+
|
194
198
|
it 'stringifys symbol keys when encoding' do
|
195
199
|
dumped_json = MultiJson.dump(:a => 1, :b => {:c => 2})
|
196
200
|
loaded_json = MultiJson.load(dumped_json)
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multi_json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bleigh
|
8
8
|
- Josh Kalderimis
|
9
9
|
- Erik Michaels-Ober
|
10
10
|
- Pavel Pravosud
|
11
|
-
autorequire:
|
11
|
+
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain:
|
14
14
|
- |
|
@@ -33,23 +33,25 @@ cert_chain:
|
|
33
33
|
7BTxdlSpJZDcAK29Ni3NRCRu6Air4wfDln0Ilzeuut6cJ4/j2/RlvsccVSRaEfOa
|
34
34
|
wM7GTK5SEdU3qelyBdc4+RRs6uU=
|
35
35
|
-----END CERTIFICATE-----
|
36
|
-
date: 2014-
|
36
|
+
date: 2014-03-05 00:00:00.000000000 Z
|
37
37
|
dependencies:
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: bundler
|
40
|
-
|
40
|
+
requirement: !ruby/object:Gem::Requirement
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
43
43
|
- !ruby/object:Gem::Version
|
44
44
|
version: '1.0'
|
45
|
-
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
48
|
requirements:
|
47
49
|
- - ~>
|
48
50
|
- !ruby/object:Gem::Version
|
49
51
|
version: '1.0'
|
50
|
-
|
51
|
-
|
52
|
-
|
52
|
+
description: A common interface to multiple JSON libraries, including Oj, Yajl, the
|
53
|
+
JSON gem (with C-extensions), the pure-Ruby JSON gem, NSJSONSerialization, gson.rb,
|
54
|
+
JrJackson, and OkJson.
|
53
55
|
email:
|
54
56
|
- michael@intridea.com
|
55
57
|
- josh.kalderimis@gmail.com
|
@@ -70,6 +72,7 @@ files:
|
|
70
72
|
- Rakefile
|
71
73
|
- lib/multi_json.rb
|
72
74
|
- lib/multi_json/adapter.rb
|
75
|
+
- lib/multi_json/adapter_error.rb
|
73
76
|
- lib/multi_json/adapters/gson.rb
|
74
77
|
- lib/multi_json/adapters/jr_jackson.rb
|
75
78
|
- lib/multi_json/adapters/json_common.rb
|
@@ -82,6 +85,7 @@ files:
|
|
82
85
|
- lib/multi_json/convertible_hash_keys.rb
|
83
86
|
- lib/multi_json/load_error.rb
|
84
87
|
- lib/multi_json/options.rb
|
88
|
+
- lib/multi_json/parse_error.rb
|
85
89
|
- lib/multi_json/vendor/okjson.rb
|
86
90
|
- lib/multi_json/version.rb
|
87
91
|
- multi_json.gemspec
|
@@ -102,7 +106,7 @@ homepage: http://github.com/intridea/multi_json
|
|
102
106
|
licenses:
|
103
107
|
- MIT
|
104
108
|
metadata: {}
|
105
|
-
post_install_message:
|
109
|
+
post_install_message:
|
106
110
|
rdoc_options: []
|
107
111
|
require_paths:
|
108
112
|
- lib
|
@@ -117,9 +121,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
121
|
- !ruby/object:Gem::Version
|
118
122
|
version: 1.3.5
|
119
123
|
requirements: []
|
120
|
-
rubyforge_project:
|
121
|
-
rubygems_version: 2.2.
|
122
|
-
signing_key:
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.2.2
|
126
|
+
signing_key:
|
123
127
|
specification_version: 4
|
124
128
|
summary: A common interface to multiple JSON libraries.
|
125
129
|
test_files:
|
@@ -131,9 +135,9 @@ test_files:
|
|
131
135
|
- spec/nsjsonserialization_adapter_spec.rb
|
132
136
|
- spec/oj_adapter_spec.rb
|
133
137
|
- spec/ok_json_adapter_spec.rb
|
134
|
-
- spec/spec_helper.rb
|
135
|
-
- spec/yajl_adapter_spec.rb
|
136
138
|
- spec/shared/adapter.rb
|
137
139
|
- spec/shared/json_common_adapter.rb
|
138
140
|
- spec/shared/options.rb
|
139
|
-
|
141
|
+
- spec/spec_helper.rb
|
142
|
+
- spec/yajl_adapter_spec.rb
|
143
|
+
has_rdoc:
|
metadata.gz.sig
CHANGED
Binary file
|