json 2.6.2 → 2.10.1
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
- data/BSDL +22 -0
- data/CHANGES.md +144 -17
- data/LEGAL +8 -0
- data/README.md +67 -224
- data/ext/json/ext/fbuffer/fbuffer.h +110 -92
- data/ext/json/ext/generator/extconf.rb +8 -2
- data/ext/json/ext/generator/generator.c +1020 -806
- data/ext/json/ext/parser/extconf.rb +7 -27
- data/ext/json/ext/parser/parser.c +1343 -3212
- data/json.gemspec +48 -52
- data/lib/json/add/bigdecimal.rb +39 -10
- data/lib/json/add/complex.rb +29 -6
- data/lib/json/add/core.rb +1 -1
- 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 +28 -6
- data/lib/json/add/regexp.rb +26 -8
- data/lib/json/add/set.rb +25 -6
- data/lib/json/add/struct.rb +29 -7
- data/lib/json/add/symbol.rb +34 -7
- data/lib/json/add/time.rb +29 -15
- data/lib/json/common.rb +418 -128
- data/lib/json/ext/generator/state.rb +106 -0
- data/lib/json/ext.rb +34 -4
- data/lib/json/generic_object.rb +7 -3
- data/lib/json/truffle_ruby/generator.rb +690 -0
- data/lib/json/version.rb +3 -7
- data/lib/json.rb +25 -21
- metadata +15 -26
- data/VERSION +0 -1
- data/ext/json/ext/generator/depend +0 -1
- data/ext/json/ext/generator/generator.h +0 -174
- data/ext/json/ext/parser/depend +0 -1
- data/ext/json/ext/parser/parser.h +0 -96
- data/ext/json/ext/parser/parser.rl +0 -986
- data/ext/json/extconf.rb +0 -3
- data/lib/json/pure/generator.rb +0 -479
- data/lib/json/pure/parser.rb +0 -337
- data/lib/json/pure.rb +0 -15
- /data/{LICENSE → COPYING} +0 -0
data/lib/json/add/set.rb
CHANGED
@@ -4,16 +4,27 @@ end
|
|
4
4
|
defined?(::Set) or require 'set'
|
5
5
|
|
6
6
|
class Set
|
7
|
-
|
8
|
-
#
|
9
|
-
# method used for JSON marshalling support.
|
7
|
+
|
8
|
+
# See #as_json.
|
10
9
|
def self.json_create(object)
|
11
10
|
new object['a']
|
12
11
|
end
|
13
12
|
|
14
|
-
#
|
13
|
+
# Methods <tt>Set#as_json</tt> and +Set.json_create+ may be used
|
14
|
+
# to serialize and deserialize a \Set object;
|
15
|
+
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
16
|
+
#
|
17
|
+
# \Method <tt>Set#as_json</tt> serializes +self+,
|
18
|
+
# returning a 2-element hash representing +self+:
|
19
|
+
#
|
20
|
+
# require 'json/add/set'
|
21
|
+
# x = Set.new(%w/foo bar baz/).as_json
|
22
|
+
# # => {"json_class"=>"Set", "a"=>["foo", "bar", "baz"]}
|
23
|
+
#
|
24
|
+
# \Method +JSON.create+ deserializes such a hash, returning a \Set object:
|
25
|
+
#
|
26
|
+
# Set.json_create(x) # => #<Set: {"foo", "bar", "baz"}>
|
15
27
|
#
|
16
|
-
# method used for JSON marshalling support.
|
17
28
|
def as_json(*)
|
18
29
|
{
|
19
30
|
JSON.create_id => self.class.name,
|
@@ -21,7 +32,15 @@ class Set
|
|
21
32
|
}
|
22
33
|
end
|
23
34
|
|
24
|
-
#
|
35
|
+
# Returns a JSON string representing +self+:
|
36
|
+
#
|
37
|
+
# require 'json/add/set'
|
38
|
+
# puts Set.new(%w/foo bar baz/).to_json
|
39
|
+
#
|
40
|
+
# Output:
|
41
|
+
#
|
42
|
+
# {"json_class":"Set","a":["foo","bar","baz"]}
|
43
|
+
#
|
25
44
|
def to_json(*args)
|
26
45
|
as_json.to_json(*args)
|
27
46
|
end
|
data/lib/json/add/struct.rb
CHANGED
@@ -1,18 +1,32 @@
|
|
1
|
-
#frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
3
3
|
require 'json'
|
4
4
|
end
|
5
5
|
|
6
6
|
class Struct
|
7
7
|
|
8
|
-
#
|
9
|
-
# <tt>v</tt> serialized by <tt>to_json</tt>.
|
8
|
+
# See #as_json.
|
10
9
|
def self.json_create(object)
|
11
10
|
new(*object['v'])
|
12
11
|
end
|
13
12
|
|
14
|
-
#
|
15
|
-
# object
|
13
|
+
# Methods <tt>Struct#as_json</tt> and +Struct.json_create+ may be used
|
14
|
+
# to serialize and deserialize a \Struct object;
|
15
|
+
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
16
|
+
#
|
17
|
+
# \Method <tt>Struct#as_json</tt> serializes +self+,
|
18
|
+
# returning a 2-element hash representing +self+:
|
19
|
+
#
|
20
|
+
# require 'json/add/struct'
|
21
|
+
# Customer = Struct.new('Customer', :name, :address, :zip)
|
22
|
+
# x = Struct::Customer.new.as_json
|
23
|
+
# # => {"json_class"=>"Struct::Customer", "v"=>[nil, nil, nil]}
|
24
|
+
#
|
25
|
+
# \Method +JSON.create+ deserializes such a hash, returning a \Struct object:
|
26
|
+
#
|
27
|
+
# Struct::Customer.json_create(x)
|
28
|
+
# # => #<struct Struct::Customer name=nil, address=nil, zip=nil>
|
29
|
+
#
|
16
30
|
def as_json(*)
|
17
31
|
klass = self.class.name
|
18
32
|
klass.to_s.empty? and raise JSON::JSONError, "Only named structs are supported!"
|
@@ -22,8 +36,16 @@ class Struct
|
|
22
36
|
}
|
23
37
|
end
|
24
38
|
|
25
|
-
#
|
26
|
-
#
|
39
|
+
# Returns a JSON string representing +self+:
|
40
|
+
#
|
41
|
+
# require 'json/add/struct'
|
42
|
+
# Customer = Struct.new('Customer', :name, :address, :zip)
|
43
|
+
# puts Struct::Customer.new.to_json
|
44
|
+
#
|
45
|
+
# Output:
|
46
|
+
#
|
47
|
+
# {"json_class":"Struct","t":{'name':'Rowdy',"age":null}}
|
48
|
+
#
|
27
49
|
def to_json(*args)
|
28
50
|
as_json.to_json(*args)
|
29
51
|
end
|
data/lib/json/add/symbol.rb
CHANGED
@@ -1,11 +1,25 @@
|
|
1
|
-
#frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
3
3
|
require 'json'
|
4
4
|
end
|
5
5
|
|
6
6
|
class Symbol
|
7
|
-
|
8
|
-
#
|
7
|
+
|
8
|
+
# Methods <tt>Symbol#as_json</tt> and +Symbol.json_create+ may be used
|
9
|
+
# to serialize and deserialize a \Symbol object;
|
10
|
+
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
11
|
+
#
|
12
|
+
# \Method <tt>Symbol#as_json</tt> serializes +self+,
|
13
|
+
# returning a 2-element hash representing +self+:
|
14
|
+
#
|
15
|
+
# require 'json/add/symbol'
|
16
|
+
# x = :foo.as_json
|
17
|
+
# # => {"json_class"=>"Symbol", "s"=>"foo"}
|
18
|
+
#
|
19
|
+
# \Method +JSON.create+ deserializes such a hash, returning a \Symbol object:
|
20
|
+
#
|
21
|
+
# Symbol.json_create(x) # => :foo
|
22
|
+
#
|
9
23
|
def as_json(*)
|
10
24
|
{
|
11
25
|
JSON.create_id => self.class.name,
|
@@ -13,12 +27,25 @@ class Symbol
|
|
13
27
|
}
|
14
28
|
end
|
15
29
|
|
16
|
-
#
|
17
|
-
|
18
|
-
|
30
|
+
# Returns a JSON string representing +self+:
|
31
|
+
#
|
32
|
+
# require 'json/add/symbol'
|
33
|
+
# puts :foo.to_json
|
34
|
+
#
|
35
|
+
# Output:
|
36
|
+
#
|
37
|
+
# # {"json_class":"Symbol","s":"foo"}
|
38
|
+
#
|
39
|
+
def to_json(state = nil, *a)
|
40
|
+
state = ::JSON::State.from_state(state)
|
41
|
+
if state.strict?
|
42
|
+
super
|
43
|
+
else
|
44
|
+
as_json.to_json(state, *a)
|
45
|
+
end
|
19
46
|
end
|
20
47
|
|
21
|
-
#
|
48
|
+
# See #as_json.
|
22
49
|
def self.json_create(o)
|
23
50
|
o['s'].to_sym
|
24
51
|
end
|
data/lib/json/add/time.rb
CHANGED
@@ -1,37 +1,51 @@
|
|
1
|
-
#frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
3
3
|
require 'json'
|
4
4
|
end
|
5
5
|
|
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
|
12
12
|
end
|
13
|
-
|
14
|
-
at(object['s'], Rational(object['n'], 1000))
|
15
|
-
else
|
16
|
-
at(object['s'], object['n'] / 1000)
|
17
|
-
end
|
13
|
+
at(object['s'], Rational(object['n'], 1000))
|
18
14
|
end
|
19
15
|
|
20
|
-
#
|
21
|
-
# object
|
16
|
+
# Methods <tt>Time#as_json</tt> and +Time.json_create+ may be used
|
17
|
+
# to serialize and deserialize a \Time object;
|
18
|
+
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
19
|
+
#
|
20
|
+
# \Method <tt>Time#as_json</tt> serializes +self+,
|
21
|
+
# returning a 2-element hash representing +self+:
|
22
|
+
#
|
23
|
+
# require 'json/add/time'
|
24
|
+
# x = Time.now.as_json
|
25
|
+
# # => {"json_class"=>"Time", "s"=>1700931656, "n"=>472846644}
|
26
|
+
#
|
27
|
+
# \Method +JSON.create+ deserializes such a hash, returning a \Time object:
|
28
|
+
#
|
29
|
+
# Time.json_create(x)
|
30
|
+
# # => 2023-11-25 11:00:56.472846644 -0600
|
31
|
+
#
|
22
32
|
def as_json(*)
|
23
|
-
nanoseconds = [ tv_usec * 1000 ]
|
24
|
-
respond_to?(:tv_nsec) and nanoseconds << tv_nsec
|
25
|
-
nanoseconds = nanoseconds.max
|
26
33
|
{
|
27
34
|
JSON.create_id => self.class.name,
|
28
35
|
's' => tv_sec,
|
29
|
-
'n' =>
|
36
|
+
'n' => tv_nsec,
|
30
37
|
}
|
31
38
|
end
|
32
39
|
|
33
|
-
#
|
34
|
-
#
|
40
|
+
# Returns a JSON string representing +self+:
|
41
|
+
#
|
42
|
+
# require 'json/add/time'
|
43
|
+
# puts Time.now.to_json
|
44
|
+
#
|
45
|
+
# Output:
|
46
|
+
#
|
47
|
+
# {"json_class":"Time","s":1700931678,"n":980650786}
|
48
|
+
#
|
35
49
|
def to_json(*args)
|
36
50
|
as_json.to_json(*args)
|
37
51
|
end
|