multi_json 1.7.1 → 1.7.2
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.tar.gz.sig +0 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +2 -1
- data/lib/multi_json.rb +14 -7
- data/lib/multi_json/adapters/{jrjackson.rb → jr_jackson.rb} +0 -0
- data/lib/multi_json/adapters/oj.rb +2 -2
- data/lib/multi_json/vendor/okjson.rb +86 -88
- data/lib/multi_json/version.rb +1 -1
- data/spec/adapter_shared_example.rb +1 -1
- data/spec/multi_json_spec.rb +38 -3
- metadata +3 -3
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
+
1.7.2
|
2
|
+
-----
|
3
|
+
* [Renamed Jrjackson adapter to JrJackson](https://github.com/intridea/multi_json/commit/b36dc915fc0e6548cbad06b5db6f520e040c9c8b)
|
4
|
+
* [Implemented jrjackson -> jr_jackson alias for back-compatability](https://github.com/intridea/multi_json/commit/aa50ab8b7bb646b8b75d5d65dfeadae8248a4f10)
|
5
|
+
* [Update vendored OkJson module](https://github.com/intridea/multi_json/commit/30a3f474e17dd86a697c3fab04f468d1a4fd69d7)
|
6
|
+
|
1
7
|
1.7.1
|
8
|
+
-----
|
2
9
|
* [Fix capitalization of JrJackson class](https://github.com/intridea/multi_json/commit/5373a5e38c647f02427a0477cb8e0e0dafad1b8d)
|
3
10
|
|
4
11
|
1.7.0
|
data/Gemfile
CHANGED
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
|
|
3
3
|
gem 'rake', '>= 0.9'
|
4
4
|
gem 'yard', '>= 0.8'
|
5
5
|
|
6
|
-
platforms :
|
6
|
+
platforms :mri do
|
7
7
|
gem 'json', '~> 1.4', :require => nil
|
8
8
|
end
|
9
9
|
|
@@ -13,6 +13,7 @@ platforms :ruby, :mswin, :mingw do
|
|
13
13
|
gem 'oj', '~> 2.0', :require => nil
|
14
14
|
gem 'yajl-ruby', '~> 1.0', :require => nil
|
15
15
|
end
|
16
|
+
|
16
17
|
platforms :jruby do
|
17
18
|
gem 'gson', '>= 0.6', :require => nil
|
18
19
|
gem 'jrjackson', :require => nil
|
data/lib/multi_json.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'multi_json/options'
|
2
|
+
require 'multi_json/version'
|
2
3
|
|
3
4
|
module MultiJson
|
4
5
|
include Options
|
@@ -26,13 +27,17 @@ module MultiJson
|
|
26
27
|
self.load_options = self.dump_options = value
|
27
28
|
end
|
28
29
|
|
30
|
+
ALIASES = {
|
31
|
+
'jrjackson' => :jr_jackson
|
32
|
+
}
|
33
|
+
|
29
34
|
REQUIREMENT_MAP = [
|
30
|
-
['oj',
|
31
|
-
['yajl',
|
32
|
-
['json',
|
33
|
-
['gson',
|
34
|
-
['
|
35
|
-
['json/pure',
|
35
|
+
['oj', :oj],
|
36
|
+
['yajl', :yajl],
|
37
|
+
['json', :json_gem],
|
38
|
+
['gson', :gson],
|
39
|
+
['jrjackson_r', :jr_jackson],
|
40
|
+
['json/pure', :json_pure]
|
36
41
|
]
|
37
42
|
|
38
43
|
# The default adapter based on what you currently
|
@@ -88,8 +93,10 @@ module MultiJson
|
|
88
93
|
def load_adapter(new_adapter)
|
89
94
|
case new_adapter
|
90
95
|
when String, Symbol
|
96
|
+
new_adapter = ALIASES.fetch(new_adapter.to_s, new_adapter)
|
91
97
|
require "multi_json/adapters/#{new_adapter}"
|
92
|
-
|
98
|
+
klass_name = new_adapter.to_s.split('_').map(&:capitalize) * ''
|
99
|
+
MultiJson::Adapters.const_get(klass_name)
|
93
100
|
when NilClass, FalseClass
|
94
101
|
load_adapter default_adapter
|
95
102
|
when Class, Module
|
File without changes
|
@@ -5,7 +5,7 @@ module MultiJson
|
|
5
5
|
module Adapters
|
6
6
|
# Use the Oj library to dump/load.
|
7
7
|
class Oj < Adapter
|
8
|
-
defaults :load, :mode => :strict
|
8
|
+
defaults :load, :mode => :strict, :symbolize_keys => false
|
9
9
|
defaults :dump, :mode => :compat, :time_format => :ruby
|
10
10
|
|
11
11
|
ParseError = if defined?(::Oj::ParseError)
|
@@ -15,7 +15,7 @@ module MultiJson
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def load(string, options={})
|
18
|
-
options[:symbol_keys] =
|
18
|
+
options[:symbol_keys] = options.delete(:symbolize_keys)
|
19
19
|
::Oj.load(string, options)
|
20
20
|
end
|
21
21
|
|
@@ -29,6 +29,7 @@ require 'stringio'
|
|
29
29
|
# http://golang.org/src/pkg/utf8/utf8.go
|
30
30
|
module MultiJson
|
31
31
|
module OkJson
|
32
|
+
Upstream = '42'
|
32
33
|
extend self
|
33
34
|
|
34
35
|
|
@@ -50,12 +51,52 @@ module MultiJson
|
|
50
51
|
end
|
51
52
|
|
52
53
|
|
54
|
+
# Encodes x into a json text. It may contain only
|
55
|
+
# Array, Hash, String, Numeric, true, false, nil.
|
56
|
+
# (Note, this list excludes Symbol.)
|
57
|
+
# X itself must be an Array or a Hash.
|
58
|
+
# No other value can be encoded, and an error will
|
59
|
+
# be raised if x contains any other value, such as
|
60
|
+
# Nan, Infinity, Symbol, and Proc, or if a Hash key
|
61
|
+
# is not a String.
|
62
|
+
# Strings contained in x must be valid UTF-8.
|
63
|
+
def encode(x)
|
64
|
+
case x
|
65
|
+
when Hash then objenc(x)
|
66
|
+
when Array then arrenc(x)
|
67
|
+
else valenc(x)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
def valenc(x)
|
73
|
+
case x
|
74
|
+
when Hash then objenc(x)
|
75
|
+
when Array then arrenc(x)
|
76
|
+
when String then strenc(x)
|
77
|
+
when Numeric then numenc(x)
|
78
|
+
when true then "true"
|
79
|
+
when false then "false"
|
80
|
+
when nil then "null"
|
81
|
+
else
|
82
|
+
if x.respond_to?(:to_json)
|
83
|
+
x.to_json
|
84
|
+
else
|
85
|
+
raise Error, "cannot encode #{x.class}: #{x.inspect}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
|
53
94
|
# Parses a "json text" in the sense of RFC 4627.
|
54
95
|
# Returns the parsed value and any trailing tokens.
|
55
96
|
# Note: this is almost the same as valparse,
|
56
97
|
# except that it does not accept atomic values.
|
57
98
|
def textparse(ts)
|
58
|
-
if ts.length
|
99
|
+
if ts.length <= 0
|
59
100
|
raise Error, 'empty'
|
60
101
|
end
|
61
102
|
|
@@ -72,7 +113,7 @@ module MultiJson
|
|
72
113
|
# Parses a "value" in the sense of RFC 4627.
|
73
114
|
# Returns the parsed value and any trailing tokens.
|
74
115
|
def valparse(ts)
|
75
|
-
if ts.length
|
116
|
+
if ts.length <= 0
|
76
117
|
raise Error, 'empty'
|
77
118
|
end
|
78
119
|
|
@@ -201,21 +242,19 @@ module MultiJson
|
|
201
242
|
# it is the lexeme.
|
202
243
|
def tok(s)
|
203
244
|
case s[0]
|
204
|
-
when ?{
|
205
|
-
when ?}
|
206
|
-
when ?:
|
207
|
-
when ?,
|
208
|
-
when ?[
|
209
|
-
when ?]
|
210
|
-
when ?n
|
211
|
-
when ?t
|
212
|
-
when ?f
|
213
|
-
when ?"
|
214
|
-
when Spc then [:space, s[0,1], s[0,1]]
|
215
|
-
|
216
|
-
|
217
|
-
when ?\r then [:space, s[0,1], s[0,1]]
|
218
|
-
else numtok(s)
|
245
|
+
when ?{ then ['{', s[0,1], s[0,1]]
|
246
|
+
when ?} then ['}', s[0,1], s[0,1]]
|
247
|
+
when ?: then [':', s[0,1], s[0,1]]
|
248
|
+
when ?, then [',', s[0,1], s[0,1]]
|
249
|
+
when ?[ then ['[', s[0,1], s[0,1]]
|
250
|
+
when ?] then [']', s[0,1], s[0,1]]
|
251
|
+
when ?n then nulltok(s)
|
252
|
+
when ?t then truetok(s)
|
253
|
+
when ?f then falsetok(s)
|
254
|
+
when ?" then strtok(s)
|
255
|
+
when Spc, ?\t, ?\n, ?\r then [:space, s[0,1], s[0,1]]
|
256
|
+
else
|
257
|
+
numtok(s)
|
219
258
|
end
|
220
259
|
end
|
221
260
|
|
@@ -228,12 +267,12 @@ module MultiJson
|
|
228
267
|
def numtok(s)
|
229
268
|
m = /-?([1-9][0-9]+|[0-9])([.][0-9]+)?([eE][+-]?[0-9]+)?/.match(s)
|
230
269
|
if m && m.begin(0) == 0
|
231
|
-
if m[
|
232
|
-
[:val, m[0], Integer(m[
|
270
|
+
if !m[2] && !m[3]
|
271
|
+
[:val, m[0], Integer(m[0])]
|
233
272
|
elsif m[2]
|
234
273
|
[:val, m[0], Float(m[0])]
|
235
274
|
else
|
236
|
-
[:val, m[0], Integer(m[
|
275
|
+
[:val, m[0], Integer(m[1])*(10**Integer(m[3][1..-1]))]
|
237
276
|
end
|
238
277
|
else
|
239
278
|
[]
|
@@ -265,17 +304,14 @@ module MultiJson
|
|
265
304
|
def unquote(q)
|
266
305
|
q = q[1...-1]
|
267
306
|
a = q.dup # allocate a big enough string
|
268
|
-
rubydoesenc = false
|
269
307
|
# In ruby >= 1.9, a[w] is a codepoint, not a byte.
|
270
|
-
if
|
308
|
+
if rubydoesenc?
|
271
309
|
a.force_encoding('UTF-8')
|
272
|
-
rubydoesenc = true
|
273
310
|
end
|
274
311
|
r, w = 0, 0
|
275
312
|
while r < q.length
|
276
313
|
c = q[r]
|
277
|
-
|
278
|
-
when c == ?\\
|
314
|
+
if c == ?\\
|
279
315
|
r += 1
|
280
316
|
if r >= q.length
|
281
317
|
raise Error, "string literal ends with a \"\\\": \"#{q}\""
|
@@ -308,7 +344,7 @@ module MultiJson
|
|
308
344
|
end
|
309
345
|
end
|
310
346
|
end
|
311
|
-
if rubydoesenc
|
347
|
+
if rubydoesenc?
|
312
348
|
a[w] = '' << uchar
|
313
349
|
w += 1
|
314
350
|
else
|
@@ -317,7 +353,7 @@ module MultiJson
|
|
317
353
|
else
|
318
354
|
raise Error, "invalid escape char #{q[r]} in \"#{q}\""
|
319
355
|
end
|
320
|
-
|
356
|
+
elsif c == ?" || c < Spc
|
321
357
|
raise Error, "invalid character in string literal \"#{q}\""
|
322
358
|
else
|
323
359
|
# Copy anything else byte-for-byte.
|
@@ -338,15 +374,14 @@ module MultiJson
|
|
338
374
|
# bytes in string a at position i.
|
339
375
|
# Returns the number of bytes written.
|
340
376
|
def ucharenc(a, i, u)
|
341
|
-
|
342
|
-
when u <= Uchar1max
|
377
|
+
if u <= Uchar1max
|
343
378
|
a[i] = (u & 0xff).chr
|
344
379
|
1
|
345
|
-
|
380
|
+
elsif u <= Uchar2max
|
346
381
|
a[i+0] = (Utag2 | ((u>>6)&0xff)).chr
|
347
382
|
a[i+1] = (Utagx | (u&Umaskx)).chr
|
348
383
|
2
|
349
|
-
|
384
|
+
elsif u <= Uchar3max
|
350
385
|
a[i+0] = (Utag3 | ((u>>12)&0xff)).chr
|
351
386
|
a[i+1] = (Utagx | ((u>>6)&Umaskx)).chr
|
352
387
|
a[i+2] = (Utagx | (u&Umaskx)).chr
|
@@ -383,54 +418,15 @@ module MultiJson
|
|
383
418
|
|
384
419
|
|
385
420
|
def nibble(c)
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
when ?A <= c && c <= ?Z then c.ord - ?A.ord + 10
|
421
|
+
if ?0 <= c && c <= ?9 then c.ord - ?0.ord
|
422
|
+
elsif ?a <= c && c <= ?z then c.ord - ?a.ord + 10
|
423
|
+
elsif ?A <= c && c <= ?Z then c.ord - ?A.ord + 10
|
390
424
|
else
|
391
425
|
raise Error, "invalid hex code #{c}"
|
392
426
|
end
|
393
427
|
end
|
394
428
|
|
395
429
|
|
396
|
-
# Encodes x into a json text. It may contain only
|
397
|
-
# Array, Hash, String, Numeric, true, false, nil.
|
398
|
-
# (Note, this list excludes Symbol.)
|
399
|
-
# X itself must be an Array or a Hash.
|
400
|
-
# No other value can be encoded, and an error will
|
401
|
-
# be raised if x contains any other value, such as
|
402
|
-
# Nan, Infinity, Symbol, and Proc, or if a Hash key
|
403
|
-
# is not a String.
|
404
|
-
# Strings contained in x must be valid UTF-8.
|
405
|
-
def encode(x)
|
406
|
-
case x
|
407
|
-
when Hash then objenc(x)
|
408
|
-
when Array then arrenc(x)
|
409
|
-
else
|
410
|
-
raise Error, 'root value must be an Array or a Hash'
|
411
|
-
end
|
412
|
-
end
|
413
|
-
|
414
|
-
|
415
|
-
def valenc(x)
|
416
|
-
case x
|
417
|
-
when Hash then objenc(x)
|
418
|
-
when Array then arrenc(x)
|
419
|
-
when String then strenc(x)
|
420
|
-
when Numeric then numenc(x)
|
421
|
-
when true then "true"
|
422
|
-
when false then "false"
|
423
|
-
when nil then "null"
|
424
|
-
else
|
425
|
-
if x.respond_to?(:to_json)
|
426
|
-
x.to_json
|
427
|
-
else
|
428
|
-
raise Error, "cannot encode #{x.class}: #{x.inspect}"
|
429
|
-
end
|
430
|
-
end
|
431
|
-
end
|
432
|
-
|
433
|
-
|
434
430
|
def objenc(x)
|
435
431
|
'{' + x.map{|k,v| keyenc(k) + ':' + valenc(v)}.join(',') + '}'
|
436
432
|
end
|
@@ -455,9 +451,6 @@ module MultiJson
|
|
455
451
|
t.putc(?")
|
456
452
|
r = 0
|
457
453
|
|
458
|
-
# In ruby >= 1.9, s[r] is a codepoint, not a byte.
|
459
|
-
rubydoesenc = s.class.method_defined?(:encoding)
|
460
|
-
|
461
454
|
while r < s.length
|
462
455
|
case s[r]
|
463
456
|
when ?" then t.print('\\"')
|
@@ -469,15 +462,15 @@ module MultiJson
|
|
469
462
|
when ?\t then t.print('\\t')
|
470
463
|
else
|
471
464
|
c = s[r]
|
472
|
-
|
473
|
-
|
465
|
+
# In ruby >= 1.9, s[r] is a codepoint, not a byte.
|
466
|
+
if rubydoesenc?
|
474
467
|
begin
|
475
468
|
c.ord # will raise an error if c is invalid UTF-8
|
476
469
|
t.write(c)
|
477
470
|
rescue
|
478
471
|
t.write(Ustrerr)
|
479
472
|
end
|
480
|
-
|
473
|
+
elsif Spc <= c && c <= ?~
|
481
474
|
t.putc(c)
|
482
475
|
else
|
483
476
|
n = ucharcopy(t, s, r) # ensure valid UTF-8 output
|
@@ -569,6 +562,11 @@ module MultiJson
|
|
569
562
|
end
|
570
563
|
|
571
564
|
|
565
|
+
def rubydoesenc?
|
566
|
+
::String.method_defined?(:force_encoding)
|
567
|
+
end
|
568
|
+
|
569
|
+
|
572
570
|
class Utf8Error < ::StandardError
|
573
571
|
end
|
574
572
|
|
@@ -577,15 +575,15 @@ module MultiJson
|
|
577
575
|
end
|
578
576
|
|
579
577
|
|
580
|
-
Utagx =
|
581
|
-
Utag2 =
|
582
|
-
Utag3 =
|
583
|
-
Utag4 =
|
584
|
-
Utag5 =
|
585
|
-
Umaskx =
|
586
|
-
Umask2 =
|
587
|
-
Umask3 =
|
588
|
-
Umask4 =
|
578
|
+
Utagx = 0b1000_0000
|
579
|
+
Utag2 = 0b1100_0000
|
580
|
+
Utag3 = 0b1110_0000
|
581
|
+
Utag4 = 0b1111_0000
|
582
|
+
Utag5 = 0b1111_1000
|
583
|
+
Umaskx = 0b0011_1111
|
584
|
+
Umask2 = 0b0001_1111
|
585
|
+
Umask3 = 0b0000_1111
|
586
|
+
Umask4 = 0b0000_0111
|
589
587
|
Uchar1max = (1<<7) - 1
|
590
588
|
Uchar2max = (1<<11) - 1
|
591
589
|
Uchar3max = (1<<16) - 1
|
data/lib/multi_json/version.rb
CHANGED
@@ -106,7 +106,7 @@ shared_examples_for 'an adapter' do |adapter|
|
|
106
106
|
|
107
107
|
# This behavior is currently not supported by gson.rb
|
108
108
|
# See discussion at https://github.com/intridea/multi_json/pull/71
|
109
|
-
unless %w(gson
|
109
|
+
unless %w(gson jr_jackson).include?(adapter)
|
110
110
|
it 'dumps custom objects that implement to_json' do
|
111
111
|
klass = Class.new do
|
112
112
|
def to_json(*)
|
data/spec/multi_json_spec.rb
CHANGED
@@ -129,6 +129,24 @@ describe 'MultiJson' do
|
|
129
129
|
}.to_not change{Symbol.all_symbols.count}
|
130
130
|
end
|
131
131
|
end
|
132
|
+
|
133
|
+
context 'with Oj.default_settings' do
|
134
|
+
|
135
|
+
around do |example|
|
136
|
+
options = Oj.default_options
|
137
|
+
Oj.default_options = { :symbol_keys => true }
|
138
|
+
MultiJson.with_engine(:oj){ example.call }
|
139
|
+
Oj.default_options = options
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'ignores global settings' do
|
143
|
+
MultiJson.with_engine(:oj) do
|
144
|
+
example = '{"a": 1, "b": 2}'
|
145
|
+
expected = { 'a' => 1, 'b' => 2 }
|
146
|
+
expect(MultiJson.load(example)).to eq expected
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
132
150
|
end
|
133
151
|
|
134
152
|
describe 'default options' do
|
@@ -148,8 +166,8 @@ describe 'MultiJson' do
|
|
148
166
|
|
149
167
|
it_behaves_like 'has options', MultiJson
|
150
168
|
|
151
|
-
%w(gson
|
152
|
-
next if !jruby? && %w(gson
|
169
|
+
%w(gson jr_jackson json_gem json_pure nsjsonserialization oj ok_json yajl).each do |adapter|
|
170
|
+
next if !jruby? && %w(gson jr_jackson).include?(adapter)
|
153
171
|
next if !macruby? && adapter == 'nsjsonserialization'
|
154
172
|
next if jruby? && %w(oj yajl).include?(adapter)
|
155
173
|
|
@@ -163,4 +181,21 @@ describe 'MultiJson' do
|
|
163
181
|
it_behaves_like 'JSON-like adapter', adapter
|
164
182
|
end
|
165
183
|
end
|
166
|
-
|
184
|
+
|
185
|
+
describe 'aliases' do
|
186
|
+
if jruby?
|
187
|
+
describe 'jrjackson' do
|
188
|
+
after{ expect(MultiJson.adapter).to eq(MultiJson::Adapters::JrJackson) }
|
189
|
+
|
190
|
+
it 'allows jrjackson alias as symbol' do
|
191
|
+
expect{ MultiJson.use :jrjackson }.not_to raise_error
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'allows jrjackson alias as string' do
|
195
|
+
expect{ MultiJson.use 'jrjackson' }.not_to raise_error
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
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.7.
|
4
|
+
version: 1.7.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -39,7 +39,7 @@ cert_chain:
|
|
39
39
|
U0xxV3ZRUnNCbHlwSGZoczZKSnVMbHlaUEdoVTNSL3YKU2YzbFZLcEJDV2dS
|
40
40
|
cEdUdnk0NVhWcEIrNTl5MzNQSm1FdVExUFRFT1l2UXlhbzlVS01BQWFBTi83
|
41
41
|
cVdRdGpsMApobHc9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
|
42
|
-
date: 2013-03-
|
42
|
+
date: 2013-03-22 00:00:00.000000000 Z
|
43
43
|
dependencies:
|
44
44
|
- !ruby/object:Gem::Dependency
|
45
45
|
name: bundler
|
@@ -85,7 +85,7 @@ files:
|
|
85
85
|
- spec/multi_json_spec.rb
|
86
86
|
- lib/multi_json/adapter.rb
|
87
87
|
- lib/multi_json/adapters/gson.rb
|
88
|
-
- lib/multi_json/adapters/
|
88
|
+
- lib/multi_json/adapters/jr_jackson.rb
|
89
89
|
- lib/multi_json/adapters/json_common.rb
|
90
90
|
- lib/multi_json/adapters/json_gem.rb
|
91
91
|
- lib/multi_json/adapters/json_pure.rb
|
metadata.gz.sig
CHANGED
Binary file
|