json 1.5.5-java → 1.6.0.1-java

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of json might be problematic. Click here for more details.

@@ -0,0 +1,25 @@
1
+ unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
2
+ require 'json'
3
+ end
4
+
5
+ # Symbol serialization/deserialization
6
+ class Symbol
7
+ # Returns a hash, that will be turned into a JSON object and represent this
8
+ # object.
9
+ def as_json(*)
10
+ {
11
+ JSON.create_id => self.class.name,
12
+ 's' => to_s,
13
+ }
14
+ end
15
+
16
+ # Stores class name (Symbol) with String representation of Symbol as a JSON string.
17
+ def to_json(*a)
18
+ as_json.to_json(*a)
19
+ end
20
+
21
+ # Deserializes JSON string by converting the <tt>string</tt> value stored in the object to a Symbol
22
+ def self.json_create(o)
23
+ o['s'].to_sym
24
+ end
25
+ end
@@ -0,0 +1,35 @@
1
+ unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
2
+ require 'json'
3
+ end
4
+
5
+ # Time serialization/deserialization
6
+ class Time
7
+
8
+ # Deserializes JSON string by converting time since epoch to Time
9
+ def self.json_create(object)
10
+ if usec = object.delete('u') # used to be tv_usec -> tv_nsec
11
+ object['n'] = usec * 1000
12
+ end
13
+ if respond_to?(:tv_nsec)
14
+ at(*object.values_at('s', 'n'))
15
+ else
16
+ at(object['s'], object['n'] / 1000)
17
+ end
18
+ end
19
+
20
+ # Returns a hash, that will be turned into a JSON object and represent this
21
+ # object.
22
+ def as_json(*)
23
+ {
24
+ JSON.create_id => self.class.name,
25
+ 's' => tv_sec,
26
+ 'n' => respond_to?(:tv_nsec) ? tv_nsec : tv_usec * 1000
27
+ }
28
+ end
29
+
30
+ # Stores class name (Time) with number of seconds since epoch and number of
31
+ # microseconds for Time as JSON string
32
+ def to_json(*args)
33
+ as_json.to_json(*args)
34
+ end
35
+ end
@@ -141,7 +141,7 @@ module JSON
141
141
  # the default.
142
142
  # * *create_additions*: If set to false, the Parser doesn't create
143
143
  # additions even if a matching class and create_id was found. This option
144
- # defaults to false.
144
+ # defaults to true.
145
145
  # * *object_class*: Defaults to Hash
146
146
  # * *array_class*: Defaults to Array
147
147
  def parse(source, opts = {})
@@ -162,7 +162,7 @@ module JSON
162
162
  # to true.
163
163
  # * *create_additions*: If set to false, the Parser doesn't create
164
164
  # additions even if a matching class and create_id was found. This option
165
- # defaults to false.
165
+ # defaults to true.
166
166
  def parse!(source, opts = {})
167
167
  opts = {
168
168
  :max_nesting => false,
@@ -287,18 +287,11 @@ module JSON
287
287
  # Load a ruby data structure from a JSON _source_ and return it. A source can
288
288
  # either be a string-like object, an IO-like object, or an object responding
289
289
  # to the read method. If _proc_ was given, it will be called with any nested
290
- # Ruby object as an argument recursively in depth first order. To modify the
291
- # default options pass in the optional _options_ argument as well.
290
+ # Ruby object as an argument recursively in depth first order.
292
291
  #
293
292
  # This method is part of the implementation of the load/dump interface of
294
293
  # Marshal and YAML.
295
- def load(source, proc = nil, options = {})
296
- load_default_options = {
297
- :max_nesting => false,
298
- :allow_nan => true,
299
- :create_additions => false
300
- }
301
- opts = load_default_options.merge options
294
+ def load(source, proc = nil)
302
295
  if source.respond_to? :to_str
303
296
  source = source.to_str
304
297
  elsif source.respond_to? :to_io
@@ -306,7 +299,7 @@ module JSON
306
299
  else
307
300
  source = source.read
308
301
  end
309
- result = parse(source, opts)
302
+ result = parse(source, :max_nesting => false, :allow_nan => true)
310
303
  recurse_proc(result, &proc) if proc
311
304
  result
312
305
  end
Binary file
Binary file
@@ -63,9 +63,9 @@ module JSON
63
63
  # * *symbolize_names*: If set to true, returns symbols for the names
64
64
  # (keys) in a JSON object. Otherwise strings are returned, which is also
65
65
  # the default.
66
- # * *create_additions*: If set to true, the Parser creates
67
- # additions when if a matching class and create_id was found. This
68
- # option defaults to false.
66
+ # * *create_additions*: If set to false, the Parser doesn't create
67
+ # additions even if a matchin class and create_id was found. This option
68
+ # defaults to true.
69
69
  # * *object_class*: Defaults to Hash
70
70
  # * *array_class*: Defaults to Array
71
71
  # * *quirks_mode*: Enables quirks_mode for parser, that is for example
@@ -88,7 +88,7 @@ module JSON
88
88
  if opts.key?(:create_additions)
89
89
  @create_additions = !!opts[:create_additions]
90
90
  else
91
- @create_additions = false
91
+ @create_additions = true
92
92
  end
93
93
  @create_id = @create_additions ? JSON.create_id : nil
94
94
  @object_class = opts[:object_class] || Hash
@@ -1,6 +1,6 @@
1
1
  module JSON
2
2
  # JSON version
3
- VERSION = '1.5.5'
3
+ VERSION = '1.6.0'
4
4
  VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -4,7 +4,6 @@
4
4
  require 'test/unit'
5
5
  require File.join(File.dirname(__FILE__), 'setup_variant')
6
6
  require 'stringio'
7
- require 'tempfile'
8
7
 
9
8
  unless Array.method_defined?(:permutation)
10
9
  begin
@@ -264,12 +263,12 @@ class TC_JSON < Test::Unit::TestCase
264
263
  def test_generation_of_core_subclasses_with_new_to_json
265
264
  obj = SubHash2["foo" => SubHash2["bar" => true]]
266
265
  obj_json = JSON(obj)
267
- obj_again = JSON.parse(obj_json, :create_additions => true)
266
+ obj_again = JSON(obj_json)
268
267
  assert_kind_of SubHash2, obj_again
269
268
  assert_kind_of SubHash2, obj_again['foo']
270
269
  assert obj_again['foo']['bar']
271
270
  assert_equal obj, obj_again
272
- assert_equal ["foo"], JSON(JSON(SubArray2["foo"]), :create_additions => true)
271
+ assert_equal ["foo"], JSON(JSON(SubArray2["foo"]))
273
272
  end
274
273
 
275
274
  def test_generation_of_core_subclasses_with_default_to_json
@@ -415,25 +414,6 @@ EOT
415
414
  JSON.parse('{"foo":"bar", "baz":"quux"}', :symbolize_names => true))
416
415
  end
417
416
 
418
- def test_load
419
- assert_equal @hash, JSON.load(@json)
420
- tempfile = Tempfile.open('json')
421
- tempfile.write @json
422
- tempfile.rewind
423
- assert_equal @hash, JSON.load(tempfile)
424
- stringio = StringIO.new(@json)
425
- stringio.rewind
426
- assert_equal @hash, JSON.load(stringio)
427
- assert_raise(NoMethodError) { JSON.load(nil) }
428
- assert_raise(JSON::ParserError) {JSON.load('') }
429
- end
430
-
431
- def test_load_with_options
432
- small_hash = JSON("foo" => 'bar')
433
- symbol_hash = { :foo => 'bar' }
434
- assert_equal symbol_hash, JSON.load(small_hash, nil, :symbolize_names => true)
435
- end
436
-
437
417
  def test_load_dump
438
418
  too_deep = '[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]'
439
419
  assert_equal too_deep, JSON.dump(eval(too_deep))
@@ -71,19 +71,11 @@ class TC_JSONAddition < Test::Unit::TestCase
71
71
  a = A.new(666)
72
72
  assert A.json_creatable?
73
73
  json = generate(a)
74
- a_again = JSON.parse(json, :create_additions => true)
74
+ a_again = JSON.parse(json)
75
75
  assert_kind_of a.class, a_again
76
76
  assert_equal a, a_again
77
77
  end
78
78
 
79
- def test_extended_json_default
80
- a = A.new(666)
81
- assert A.json_creatable?
82
- json = generate(a)
83
- a_hash = JSON.parse(json)
84
- assert_kind_of Hash, a_hash
85
- end
86
-
87
79
  def test_extended_json_disabled
88
80
  a = A.new(666)
89
81
  assert A.json_creatable?
@@ -110,7 +102,7 @@ class TC_JSONAddition < Test::Unit::TestCase
110
102
  c = C.new
111
103
  assert !C.json_creatable?
112
104
  json = generate(c)
113
- assert_raises(ArgumentError, NameError) { JSON.parse(json, :create_additions => true) }
105
+ assert_raises(ArgumentError, NameError) { JSON.parse(json) }
114
106
  end
115
107
 
116
108
  def test_raw_strings
@@ -128,7 +120,7 @@ class TC_JSONAddition < Test::Unit::TestCase
128
120
  assert_match(/\A\{.*\}\Z/, json)
129
121
  assert_match(/"json_class":"String"/, json)
130
122
  assert_match(/"raw":\[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255\]/, json)
131
- raw_again = JSON.parse(json, :create_additions => true)
123
+ raw_again = JSON.parse(json)
132
124
  assert_equal raw, raw_again
133
125
  end
134
126
 
@@ -136,17 +128,17 @@ class TC_JSONAddition < Test::Unit::TestCase
136
128
 
137
129
  def test_core
138
130
  t = Time.now
139
- assert_equal t, JSON(JSON(t), :create_additions => true)
131
+ assert_equal t.inspect, JSON(JSON(t)).inspect
140
132
  d = Date.today
141
- assert_equal d, JSON(JSON(d), :create_additions => true)
133
+ assert_equal d, JSON(JSON(d))
142
134
  d = DateTime.civil(2007, 6, 14, 14, 57, 10, Rational(1, 12), 2299161)
143
- assert_equal d, JSON(JSON(d), :create_additions => true)
144
- assert_equal 1..10, JSON(JSON(1..10), :create_additions => true)
145
- assert_equal 1...10, JSON(JSON(1...10), :create_additions => true)
146
- assert_equal "a".."c", JSON(JSON("a".."c"), :create_additions => true)
147
- assert_equal "a"..."c", JSON(JSON("a"..."c"), :create_additions => true)
135
+ assert_equal d, JSON(JSON(d))
136
+ assert_equal 1..10, JSON(JSON(1..10))
137
+ assert_equal 1...10, JSON(JSON(1...10))
138
+ assert_equal "a".."c", JSON(JSON("a".."c"))
139
+ assert_equal "a"..."c", JSON(JSON("a"..."c"))
148
140
  s = MyJsonStruct.new 4711, 'foot'
149
- assert_equal s, JSON(JSON(s), :create_additions => true)
141
+ assert_equal s, JSON(JSON(s))
150
142
  struct = Struct.new :foo, :bar
151
143
  s = struct.new 4711, 'foot'
152
144
  assert_raises(JSONError) { JSON(s) }
@@ -154,29 +146,29 @@ class TC_JSONAddition < Test::Unit::TestCase
154
146
  raise TypeError, "test me"
155
147
  rescue TypeError => e
156
148
  e_json = JSON.generate e
157
- e_again = JSON e_json, :create_additions => true
149
+ e_again = JSON e_json
158
150
  assert_kind_of TypeError, e_again
159
151
  assert_equal e.message, e_again.message
160
152
  assert_equal e.backtrace, e_again.backtrace
161
153
  end
162
- assert_equal(/foo/, JSON(JSON(/foo/), :create_additions => true))
163
- assert_equal(/foo/i, JSON(JSON(/foo/i), :create_additions => true))
154
+ assert_equal(/foo/, JSON(JSON(/foo/)))
155
+ assert_equal(/foo/i, JSON(JSON(/foo/i)))
164
156
  end
165
157
 
166
158
  def test_utc_datetime
167
159
  now = Time.now
168
- d = DateTime.parse(now.to_s, :create_additions => true) # usual case
169
- assert_equal d, JSON.parse(d.to_json, :create_additions => true)
160
+ d = DateTime.parse(now.to_s) # usual case
161
+ assert_equal d, JSON.parse(d.to_json)
170
162
  d = DateTime.parse(now.utc.to_s) # of = 0
171
- assert_equal d, JSON.parse(d.to_json, :create_additions => true)
163
+ assert_equal d, JSON.parse(d.to_json)
172
164
  d = DateTime.civil(2008, 6, 17, 11, 48, 32, Rational(1,24))
173
- assert_equal d, JSON.parse(d.to_json, :create_additions => true)
165
+ assert_equal d, JSON.parse(d.to_json)
174
166
  d = DateTime.civil(2008, 6, 17, 11, 48, 32, Rational(12,24))
175
- assert_equal d, JSON.parse(d.to_json, :create_additions => true)
167
+ assert_equal d, JSON.parse(d.to_json)
176
168
  end
177
169
 
178
170
  def test_rational_complex
179
- assert_equal Rational(2, 9), JSON.parse(JSON(Rational(2, 9)), :create_additions => true)
180
- assert_equal Complex(2, 9), JSON.parse(JSON(Complex(2, 9)), :create_additions => true)
171
+ assert_equal Rational(2, 9), JSON(JSON(Rational(2, 9)))
172
+ assert_equal Complex(2, 9), JSON(JSON(Complex(2, 9)))
181
173
  end
182
174
  end
@@ -27,13 +27,14 @@ class TestJsonStringMatching < Test::Unit::TestCase
27
27
  t = TestTime.new
28
28
  t_json = [ t ].to_json
29
29
  assert_equal [ t ],
30
- JSON.parse(t_json, :create_additions => true,
31
- :match_string => { /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\z/ => TestTime })
30
+ JSON.parse(t_json,
31
+ :match_string => { /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\Z/ => TestTime })
32
32
  assert_equal [ t.strftime('%FT%T%z') ],
33
- JSON.parse(t_json, :create_additions => true,
34
- :match_string => { /\A\d{3}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\z/ => TestTime })
33
+ JSON.parse(t_json,
34
+ :match_string => { /\A\d{3}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\Z/ => TestTime })
35
35
  assert_equal [ t.strftime('%FT%T%z') ],
36
36
  JSON.parse(t_json,
37
- :match_string => { /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\z/ => TestTime })
37
+ :match_string => { /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}\Z/ => TestTime },
38
+ :create_additions => false)
38
39
  end
39
40
  end
metadata CHANGED
@@ -1,113 +1,112 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: json
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.5.5
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.6.0.1
6
6
  platform: java
7
- authors:
8
- - Daniel Luz
9
- autorequire:
7
+ authors:
8
+ - Daniel Luz
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-10 00:00:00.000000000 Z
12
+
13
+ date: 2011-09-13 00:00:00 Z
13
14
  dependencies: []
15
+
14
16
  description: A JSON implementation as a JRuby extension.
15
17
  email: dev+ruby@mernen.com
16
18
  executables: []
19
+
17
20
  extensions: []
21
+
18
22
  extra_rdoc_files: []
19
- files:
20
- - lib/json.rb
21
- - lib/json/json.xpm
22
- - lib/json/TrueClass.xpm
23
- - lib/json/version.rb
24
- - lib/json/Array.xpm
25
- - lib/json/common.rb
26
- - lib/json/ext.rb
27
- - lib/json/pure.rb
28
- - lib/json/Key.xpm
29
- - lib/json/FalseClass.xpm
30
- - lib/json/editor.rb
31
- - lib/json/Numeric.xpm
32
- - lib/json/NilClass.xpm
33
- - lib/json/String.xpm
34
- - lib/json/Hash.xpm
35
- - lib/json/add/complex.rb
36
- - lib/json/add/rational.rb
37
- - lib/json/add/core.rb
38
- - lib/json/pure/generator.rb
39
- - lib/json/pure/parser.rb
40
- - lib/json/ext/generator.jar
41
- - lib/json/ext/parser.jar
42
- - tests/test_json_string_matching.rb
43
- - tests/test_json_fixtures.rb
44
- - tests/setup_variant.rb
45
- - tests/test_json_unicode.rb
46
- - tests/test_json_addition.rb
47
- - tests/test_json_generate.rb
48
- - tests/test_json_encoding.rb
49
- - tests/test_json.rb
50
- - tests/fixtures/fail6.json
51
- - tests/fixtures/fail9.json
52
- - tests/fixtures/fail10.json
53
- - tests/fixtures/fail24.json
54
- - tests/fixtures/fail28.json
55
- - tests/fixtures/fail13.json
56
- - tests/fixtures/fail4.json
57
- - tests/fixtures/pass3.json
58
- - tests/fixtures/fail11.json
59
- - tests/fixtures/fail14.json
60
- - tests/fixtures/fail3.json
61
- - tests/fixtures/fail12.json
62
- - tests/fixtures/pass16.json
63
- - tests/fixtures/pass15.json
64
- - tests/fixtures/fail20.json
65
- - tests/fixtures/fail8.json
66
- - tests/fixtures/pass2.json
67
- - tests/fixtures/fail5.json
68
- - tests/fixtures/fail1.json
69
- - tests/fixtures/fail25.json
70
- - tests/fixtures/pass17.json
71
- - tests/fixtures/fail7.json
72
- - tests/fixtures/pass26.json
73
- - tests/fixtures/fail21.json
74
- - tests/fixtures/pass1.json
75
- - tests/fixtures/fail23.json
76
- - tests/fixtures/fail18.json
77
- - tests/fixtures/fail2.json
78
- - tests/fixtures/fail22.json
79
- - tests/fixtures/fail27.json
80
- - tests/fixtures/fail19.json
23
+
24
+ files:
25
+ - lib/json.rb
26
+ - lib/json/common.rb
27
+ - lib/json/ext.rb
28
+ - lib/json/pure.rb
29
+ - lib/json/version.rb
30
+ - lib/json/add/complex.rb
31
+ - lib/json/add/core.rb
32
+ - lib/json/add/date.rb
33
+ - lib/json/add/date_time.rb
34
+ - lib/json/add/exception.rb
35
+ - lib/json/add/range.rb
36
+ - lib/json/add/rational.rb
37
+ - lib/json/add/regexp.rb
38
+ - lib/json/add/struct.rb
39
+ - lib/json/add/symbol.rb
40
+ - lib/json/add/time.rb
41
+ - lib/json/ext/generator.jar
42
+ - lib/json/ext/parser.jar
43
+ - lib/json/pure/generator.rb
44
+ - lib/json/pure/parser.rb
45
+ - tests/setup_variant.rb
46
+ - tests/test_json.rb
47
+ - tests/test_json_addition.rb
48
+ - tests/test_json_encoding.rb
49
+ - tests/test_json_fixtures.rb
50
+ - tests/test_json_generate.rb
51
+ - tests/test_json_string_matching.rb
52
+ - tests/test_json_unicode.rb
53
+ - tests/fixtures/fail1.json
54
+ - tests/fixtures/fail10.json
55
+ - tests/fixtures/fail11.json
56
+ - tests/fixtures/fail12.json
57
+ - tests/fixtures/fail13.json
58
+ - tests/fixtures/fail14.json
59
+ - tests/fixtures/fail18.json
60
+ - tests/fixtures/fail19.json
61
+ - tests/fixtures/fail2.json
62
+ - tests/fixtures/fail20.json
63
+ - tests/fixtures/fail21.json
64
+ - tests/fixtures/fail22.json
65
+ - tests/fixtures/fail23.json
66
+ - tests/fixtures/fail24.json
67
+ - tests/fixtures/fail25.json
68
+ - tests/fixtures/fail27.json
69
+ - tests/fixtures/fail28.json
70
+ - tests/fixtures/fail3.json
71
+ - tests/fixtures/fail4.json
72
+ - tests/fixtures/fail5.json
73
+ - tests/fixtures/fail6.json
74
+ - tests/fixtures/fail7.json
75
+ - tests/fixtures/fail8.json
76
+ - tests/fixtures/fail9.json
77
+ - tests/fixtures/pass1.json
78
+ - tests/fixtures/pass15.json
79
+ - tests/fixtures/pass16.json
80
+ - tests/fixtures/pass17.json
81
+ - tests/fixtures/pass2.json
82
+ - tests/fixtures/pass26.json
83
+ - tests/fixtures/pass3.json
81
84
  homepage: http://json-jruby.rubyforge.org/
82
85
  licenses: []
83
- post_install_message:
86
+
87
+ post_install_message:
84
88
  rdoc_options: []
85
- require_paths:
86
- - lib
87
- required_ruby_version: !ruby/object:Gem::Requirement
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- segments:
92
- - 0
93
- hash: 2
94
- version: !binary |-
95
- MA==
89
+
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
96
93
  none: false
97
- required_rubygems_version: !ruby/object:Gem::Requirement
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- segments:
102
- - 0
103
- hash: 2
104
- version: !binary |-
105
- MA==
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: "0"
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
99
  none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: "0"
107
104
  requirements: []
105
+
108
106
  rubyforge_project: json-jruby
109
- rubygems_version: 1.8.24
110
- signing_key:
107
+ rubygems_version: 1.8.9
108
+ signing_key:
111
109
  specification_version: 3
112
110
  summary: JSON implementation for JRuby
113
111
  test_files: []
112
+