json 1.8.6 → 2.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/{CHANGES → CHANGES.md} +292 -96
- data/LICENSE +56 -0
- data/README.md +185 -114
- data/ext/json/ext/fbuffer/fbuffer.h +0 -3
- data/ext/json/ext/generator/generator.c +328 -117
- data/ext/json/ext/generator/generator.h +8 -8
- data/ext/json/ext/parser/extconf.rb +29 -0
- data/ext/json/ext/parser/parser.c +540 -569
- data/ext/json/ext/parser/parser.h +10 -6
- data/ext/json/ext/parser/parser.rl +269 -261
- data/ext/json/extconf.rb +1 -1
- data/json.gemspec +0 -0
- data/lib/json/add/bigdecimal.rb +40 -10
- data/lib/json/add/complex.rb +32 -9
- data/lib/json/add/core.rb +1 -0
- data/lib/json/add/date.rb +27 -7
- data/lib/json/add/date_time.rb +26 -9
- data/lib/json/add/exception.rb +25 -7
- data/lib/json/add/ostruct.rb +32 -9
- data/lib/json/add/range.rb +33 -8
- data/lib/json/add/rational.rb +30 -8
- data/lib/json/add/regexp.rb +28 -10
- data/lib/json/add/set.rb +48 -0
- data/lib/json/add/struct.rb +29 -7
- data/lib/json/add/symbol.rb +28 -5
- data/lib/json/add/time.rb +27 -6
- data/lib/json/common.rb +402 -188
- data/lib/json/ext.rb +0 -6
- data/lib/json/generic_object.rb +11 -6
- data/lib/json/pure/generator.rb +120 -137
- data/lib/json/pure/parser.rb +64 -86
- data/lib/json/pure.rb +2 -8
- data/lib/json/version.rb +2 -1
- data/lib/json.rb +559 -29
- metadata +18 -129
- data/.gitignore +0 -17
- data/.travis.yml +0 -18
- data/Gemfile +0 -7
- data/README-json-jruby.markdown +0 -33
- data/Rakefile +0 -402
- data/TODO +0 -1
- data/VERSION +0 -1
- data/data/example.json +0 -1
- data/data/index.html +0 -38
- data/data/prototype.js +0 -4184
- data/diagrams/.keep +0 -0
- data/install.rb +0 -23
- data/java/src/json/ext/ByteListTranscoder.java +0 -166
- data/java/src/json/ext/Generator.java +0 -446
- data/java/src/json/ext/GeneratorMethods.java +0 -231
- data/java/src/json/ext/GeneratorService.java +0 -42
- data/java/src/json/ext/GeneratorState.java +0 -542
- data/java/src/json/ext/OptionsReader.java +0 -113
- data/java/src/json/ext/Parser.java +0 -2644
- data/java/src/json/ext/Parser.rl +0 -968
- data/java/src/json/ext/ParserService.java +0 -34
- data/java/src/json/ext/RuntimeInfo.java +0 -120
- data/java/src/json/ext/StringDecoder.java +0 -166
- data/java/src/json/ext/StringEncoder.java +0 -111
- data/java/src/json/ext/Utils.java +0 -88
- data/json-java.gemspec +0 -38
- data/json_pure.gemspec +0 -37
- data/lib/json/ext/.keep +0 -0
- data/tests/fixtures/fail1.json +0 -1
- data/tests/fixtures/fail10.json +0 -1
- data/tests/fixtures/fail11.json +0 -1
- data/tests/fixtures/fail12.json +0 -1
- data/tests/fixtures/fail13.json +0 -1
- data/tests/fixtures/fail14.json +0 -1
- data/tests/fixtures/fail18.json +0 -1
- data/tests/fixtures/fail19.json +0 -1
- data/tests/fixtures/fail2.json +0 -1
- data/tests/fixtures/fail20.json +0 -1
- data/tests/fixtures/fail21.json +0 -1
- data/tests/fixtures/fail22.json +0 -1
- data/tests/fixtures/fail23.json +0 -1
- data/tests/fixtures/fail24.json +0 -1
- data/tests/fixtures/fail25.json +0 -1
- data/tests/fixtures/fail27.json +0 -2
- data/tests/fixtures/fail28.json +0 -2
- data/tests/fixtures/fail3.json +0 -1
- data/tests/fixtures/fail4.json +0 -1
- data/tests/fixtures/fail5.json +0 -1
- data/tests/fixtures/fail6.json +0 -1
- data/tests/fixtures/fail7.json +0 -1
- data/tests/fixtures/fail8.json +0 -1
- data/tests/fixtures/fail9.json +0 -1
- data/tests/fixtures/pass1.json +0 -56
- data/tests/fixtures/pass15.json +0 -1
- data/tests/fixtures/pass16.json +0 -1
- data/tests/fixtures/pass17.json +0 -1
- data/tests/fixtures/pass2.json +0 -1
- data/tests/fixtures/pass26.json +0 -1
- data/tests/fixtures/pass3.json +0 -6
- data/tests/setup_variant.rb +0 -11
- data/tests/test_json.rb +0 -519
- data/tests/test_json_addition.rb +0 -196
- data/tests/test_json_encoding.rb +0 -65
- data/tests/test_json_fixtures.rb +0 -35
- data/tests/test_json_generate.rb +0 -348
- data/tests/test_json_generic_object.rb +0 -75
- data/tests/test_json_string_matching.rb +0 -39
- data/tests/test_json_unicode.rb +0 -72
- data/tools/diff.sh +0 -18
- data/tools/fuzz.rb +0 -139
- data/tools/server.rb +0 -62
data/lib/json/add/symbol.rb
CHANGED
@@ -1,11 +1,26 @@
|
|
1
|
+
|
2
|
+
#frozen_string_literal: false
|
1
3
|
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
2
4
|
require 'json'
|
3
5
|
end
|
4
6
|
|
5
|
-
# Symbol serialization/deserialization
|
6
7
|
class Symbol
|
7
|
-
|
8
|
-
#
|
8
|
+
|
9
|
+
# Methods <tt>Symbol#as_json</tt> and +Symbol.json_create+ may be used
|
10
|
+
# to serialize and deserialize a \Symbol object;
|
11
|
+
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
12
|
+
#
|
13
|
+
# \Method <tt>Symbol#as_json</tt> serializes +self+,
|
14
|
+
# returning a 2-element hash representing +self+:
|
15
|
+
#
|
16
|
+
# require 'json/add/symbol'
|
17
|
+
# x = :foo.as_json
|
18
|
+
# # => {"json_class"=>"Symbol", "s"=>"foo"}
|
19
|
+
#
|
20
|
+
# \Method +JSON.create+ deserializes such a hash, returning a \Symbol object:
|
21
|
+
#
|
22
|
+
# Symbol.json_create(x) # => :foo
|
23
|
+
#
|
9
24
|
def as_json(*)
|
10
25
|
{
|
11
26
|
JSON.create_id => self.class.name,
|
@@ -13,12 +28,20 @@ class Symbol
|
|
13
28
|
}
|
14
29
|
end
|
15
30
|
|
16
|
-
#
|
31
|
+
# Returns a JSON string representing +self+:
|
32
|
+
#
|
33
|
+
# require 'json/add/symbol'
|
34
|
+
# puts :foo.to_json
|
35
|
+
#
|
36
|
+
# Output:
|
37
|
+
#
|
38
|
+
# # {"json_class":"Symbol","s":"foo"}
|
39
|
+
#
|
17
40
|
def to_json(*a)
|
18
41
|
as_json.to_json(*a)
|
19
42
|
end
|
20
43
|
|
21
|
-
#
|
44
|
+
# See #as_json.
|
22
45
|
def self.json_create(o)
|
23
46
|
o['s'].to_sym
|
24
47
|
end
|
data/lib/json/add/time.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
+
#frozen_string_literal: false
|
1
2
|
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
2
3
|
require 'json'
|
3
4
|
end
|
4
5
|
|
5
|
-
# Time serialization/deserialization
|
6
6
|
class Time
|
7
7
|
|
8
|
-
#
|
8
|
+
# See #as_json.
|
9
9
|
def self.json_create(object)
|
10
10
|
if usec = object.delete('u') # used to be tv_usec -> tv_nsec
|
11
11
|
object['n'] = usec * 1000
|
@@ -17,8 +17,22 @@ class Time
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
#
|
21
|
-
# object
|
20
|
+
# Methods <tt>Time#as_json</tt> and +Time.json_create+ may be used
|
21
|
+
# to serialize and deserialize a \Time object;
|
22
|
+
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
23
|
+
#
|
24
|
+
# \Method <tt>Time#as_json</tt> serializes +self+,
|
25
|
+
# returning a 2-element hash representing +self+:
|
26
|
+
#
|
27
|
+
# require 'json/add/time'
|
28
|
+
# x = Time.now.as_json
|
29
|
+
# # => {"json_class"=>"Time", "s"=>1700931656, "n"=>472846644}
|
30
|
+
#
|
31
|
+
# \Method +JSON.create+ deserializes such a hash, returning a \Time object:
|
32
|
+
#
|
33
|
+
# Time.json_create(x)
|
34
|
+
# # => 2023-11-25 11:00:56.472846644 -0600
|
35
|
+
#
|
22
36
|
def as_json(*)
|
23
37
|
nanoseconds = [ tv_usec * 1000 ]
|
24
38
|
respond_to?(:tv_nsec) and nanoseconds << tv_nsec
|
@@ -30,8 +44,15 @@ class Time
|
|
30
44
|
}
|
31
45
|
end
|
32
46
|
|
33
|
-
#
|
34
|
-
#
|
47
|
+
# Returns a JSON string representing +self+:
|
48
|
+
#
|
49
|
+
# require 'json/add/time'
|
50
|
+
# puts Time.now.to_json
|
51
|
+
#
|
52
|
+
# Output:
|
53
|
+
#
|
54
|
+
# {"json_class":"Time","s":1700931678,"n":980650786}
|
55
|
+
#
|
35
56
|
def to_json(*args)
|
36
57
|
as_json.to_json(*args)
|
37
58
|
end
|