json 2.7.0-java → 2.7.2-java
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/lib/json/add/bigdecimal.rb +32 -6
- data/lib/json/add/complex.rb +28 -5
- data/lib/json/add/date.rb +26 -6
- data/lib/json/add/date_time.rb +25 -8
- data/lib/json/add/exception.rb +24 -6
- data/lib/json/add/ostruct.rb +31 -8
- data/lib/json/add/range.rb +25 -15
- data/lib/json/add/rational.rb +27 -5
- data/lib/json/add/regexp.rb +25 -7
- data/lib/json/add/set.rb +25 -6
- data/lib/json/add/struct.rb +28 -6
- data/lib/json/add/symbol.rb +27 -4
- data/lib/json/add/time.rb +26 -5
- data/lib/json/common.rb +20 -9
- data/lib/json/ext/generator.jar +0 -0
- data/lib/json/ext/parser.jar +0 -0
- data/lib/json/generic_object.rb +6 -2
- data/lib/json/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz: '
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '0297e625e262e4e540edbe6b50f6c6f9463149c31bbeffd8815372d973985ddb'
|
|
4
|
+
data.tar.gz: 8f63fd93dd6574a60cc2debd2172fe61e8acbf76c7a3b955a09362caff8eaca2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3ee412792d92371db5ee0b521bd1076e1e45bcc06c8f92ad23c46cc5919c849209e24d29f3056e4d052f8a3a9dc5eb4479549ad5c46481e1d9bb43208d768380
|
|
7
|
+
data.tar.gz: fa594f7d4346e79e64263b04d1bb1a4c2e46e7ad28cdd27159870887ea5fbbc09843abe5758a777b154639fa56a1dd69c0b309cd46a9aba904fec725ab1c3e46
|
data/lib/json/add/bigdecimal.rb
CHANGED
|
@@ -8,16 +8,30 @@ rescue LoadError
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
class BigDecimal
|
|
11
|
-
|
|
12
|
-
#
|
|
13
|
-
# method used for JSON marshalling support.
|
|
11
|
+
|
|
12
|
+
# See #as_json.
|
|
14
13
|
def self.json_create(object)
|
|
15
14
|
BigDecimal._load object['b']
|
|
16
15
|
end
|
|
17
16
|
|
|
18
|
-
#
|
|
17
|
+
# Methods <tt>BigDecimal#as_json</tt> and +BigDecimal.json_create+ may be used
|
|
18
|
+
# to serialize and deserialize a \BigDecimal object;
|
|
19
|
+
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
|
20
|
+
#
|
|
21
|
+
# \Method <tt>BigDecimal#as_json</tt> serializes +self+,
|
|
22
|
+
# returning a 2-element hash representing +self+:
|
|
23
|
+
#
|
|
24
|
+
# require 'json/add/bigdecimal'
|
|
25
|
+
# x = BigDecimal(2).as_json # => {"json_class"=>"BigDecimal", "b"=>"27:0.2e1"}
|
|
26
|
+
# y = BigDecimal(2.0, 4).as_json # => {"json_class"=>"BigDecimal", "b"=>"36:0.2e1"}
|
|
27
|
+
# z = BigDecimal(Complex(2, 0)).as_json # => {"json_class"=>"BigDecimal", "b"=>"27:0.2e1"}
|
|
28
|
+
#
|
|
29
|
+
# \Method +JSON.create+ deserializes such a hash, returning a \BigDecimal object:
|
|
30
|
+
#
|
|
31
|
+
# BigDecimal.json_create(x) # => 0.2e1
|
|
32
|
+
# BigDecimal.json_create(y) # => 0.2e1
|
|
33
|
+
# BigDecimal.json_create(z) # => 0.2e1
|
|
19
34
|
#
|
|
20
|
-
# method used for JSON marshalling support.
|
|
21
35
|
def as_json(*)
|
|
22
36
|
{
|
|
23
37
|
JSON.create_id => self.class.name,
|
|
@@ -25,7 +39,19 @@ class BigDecimal
|
|
|
25
39
|
}
|
|
26
40
|
end
|
|
27
41
|
|
|
28
|
-
#
|
|
42
|
+
# Returns a JSON string representing +self+:
|
|
43
|
+
#
|
|
44
|
+
# require 'json/add/bigdecimal'
|
|
45
|
+
# puts BigDecimal(2).to_json
|
|
46
|
+
# puts BigDecimal(2.0, 4).to_json
|
|
47
|
+
# puts BigDecimal(Complex(2, 0)).to_json
|
|
48
|
+
#
|
|
49
|
+
# Output:
|
|
50
|
+
#
|
|
51
|
+
# {"json_class":"BigDecimal","b":"27:0.2e1"}
|
|
52
|
+
# {"json_class":"BigDecimal","b":"36:0.2e1"}
|
|
53
|
+
# {"json_class":"BigDecimal","b":"27:0.2e1"}
|
|
54
|
+
#
|
|
29
55
|
def to_json(*args)
|
|
30
56
|
as_json.to_json(*args)
|
|
31
57
|
end
|
data/lib/json/add/complex.rb
CHANGED
|
@@ -5,14 +5,27 @@ end
|
|
|
5
5
|
|
|
6
6
|
class Complex
|
|
7
7
|
|
|
8
|
-
#
|
|
9
|
-
# value <tt>i</tt>, to a Complex object.
|
|
8
|
+
# See #as_json.
|
|
10
9
|
def self.json_create(object)
|
|
11
10
|
Complex(object['r'], object['i'])
|
|
12
11
|
end
|
|
13
12
|
|
|
14
|
-
#
|
|
15
|
-
# object
|
|
13
|
+
# Methods <tt>Complex#as_json</tt> and +Complex.json_create+ may be used
|
|
14
|
+
# to serialize and deserialize a \Complex object;
|
|
15
|
+
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
|
16
|
+
#
|
|
17
|
+
# \Method <tt>Complex#as_json</tt> serializes +self+,
|
|
18
|
+
# returning a 2-element hash representing +self+:
|
|
19
|
+
#
|
|
20
|
+
# require 'json/add/complex'
|
|
21
|
+
# x = Complex(2).as_json # => {"json_class"=>"Complex", "r"=>2, "i"=>0}
|
|
22
|
+
# y = Complex(2.0, 4).as_json # => {"json_class"=>"Complex", "r"=>2.0, "i"=>4}
|
|
23
|
+
#
|
|
24
|
+
# \Method +JSON.create+ deserializes such a hash, returning a \Complex object:
|
|
25
|
+
#
|
|
26
|
+
# Complex.json_create(x) # => (2+0i)
|
|
27
|
+
# Complex.json_create(y) # => (2.0+4i)
|
|
28
|
+
#
|
|
16
29
|
def as_json(*)
|
|
17
30
|
{
|
|
18
31
|
JSON.create_id => self.class.name,
|
|
@@ -21,7 +34,17 @@ class Complex
|
|
|
21
34
|
}
|
|
22
35
|
end
|
|
23
36
|
|
|
24
|
-
#
|
|
37
|
+
# Returns a JSON string representing +self+:
|
|
38
|
+
#
|
|
39
|
+
# require 'json/add/complex'
|
|
40
|
+
# puts Complex(2).to_json
|
|
41
|
+
# puts Complex(2.0, 4).to_json
|
|
42
|
+
#
|
|
43
|
+
# Output:
|
|
44
|
+
#
|
|
45
|
+
# {"json_class":"Complex","r":2,"i":0}
|
|
46
|
+
# {"json_class":"Complex","r":2.0,"i":4}
|
|
47
|
+
#
|
|
25
48
|
def to_json(*args)
|
|
26
49
|
as_json.to_json(*args)
|
|
27
50
|
end
|
data/lib/json/add/date.rb
CHANGED
|
@@ -6,16 +6,29 @@ require 'date'
|
|
|
6
6
|
|
|
7
7
|
class Date
|
|
8
8
|
|
|
9
|
-
#
|
|
10
|
-
# <tt>m</tt>, day <tt>d</tt> and Day of Calendar Reform <tt>sg</tt> to Date.
|
|
9
|
+
# See #as_json.
|
|
11
10
|
def self.json_create(object)
|
|
12
11
|
civil(*object.values_at('y', 'm', 'd', 'sg'))
|
|
13
12
|
end
|
|
14
13
|
|
|
15
14
|
alias start sg unless method_defined?(:start)
|
|
16
15
|
|
|
17
|
-
#
|
|
18
|
-
# object
|
|
16
|
+
# Methods <tt>Date#as_json</tt> and +Date.json_create+ may be used
|
|
17
|
+
# to serialize and deserialize a \Date object;
|
|
18
|
+
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
|
19
|
+
#
|
|
20
|
+
# \Method <tt>Date#as_json</tt> serializes +self+,
|
|
21
|
+
# returning a 2-element hash representing +self+:
|
|
22
|
+
#
|
|
23
|
+
# require 'json/add/date'
|
|
24
|
+
# x = Date.today.as_json
|
|
25
|
+
# # => {"json_class"=>"Date", "y"=>2023, "m"=>11, "d"=>21, "sg"=>2299161.0}
|
|
26
|
+
#
|
|
27
|
+
# \Method +JSON.create+ deserializes such a hash, returning a \Date object:
|
|
28
|
+
#
|
|
29
|
+
# Date.json_create(x)
|
|
30
|
+
# # => #<Date: 2023-11-21 ((2460270j,0s,0n),+0s,2299161j)>
|
|
31
|
+
#
|
|
19
32
|
def as_json(*)
|
|
20
33
|
{
|
|
21
34
|
JSON.create_id => self.class.name,
|
|
@@ -26,8 +39,15 @@ class Date
|
|
|
26
39
|
}
|
|
27
40
|
end
|
|
28
41
|
|
|
29
|
-
#
|
|
30
|
-
#
|
|
42
|
+
# Returns a JSON string representing +self+:
|
|
43
|
+
#
|
|
44
|
+
# require 'json/add/date'
|
|
45
|
+
# puts Date.today.to_json
|
|
46
|
+
#
|
|
47
|
+
# Output:
|
|
48
|
+
#
|
|
49
|
+
# {"json_class":"Date","y":2023,"m":11,"d":21,"sg":2299161.0}
|
|
50
|
+
#
|
|
31
51
|
def to_json(*args)
|
|
32
52
|
as_json.to_json(*args)
|
|
33
53
|
end
|
data/lib/json/add/date_time.rb
CHANGED
|
@@ -6,9 +6,7 @@ require 'date'
|
|
|
6
6
|
|
|
7
7
|
class DateTime
|
|
8
8
|
|
|
9
|
-
#
|
|
10
|
-
# day <tt>d</tt>, hour <tt>H</tt>, minute <tt>M</tt>, second <tt>S</tt>,
|
|
11
|
-
# offset <tt>of</tt> and Day of Calendar Reform <tt>sg</tt> to DateTime.
|
|
9
|
+
# See #as_json.
|
|
12
10
|
def self.json_create(object)
|
|
13
11
|
args = object.values_at('y', 'm', 'd', 'H', 'M', 'S')
|
|
14
12
|
of_a, of_b = object['of'].split('/')
|
|
@@ -23,8 +21,21 @@ class DateTime
|
|
|
23
21
|
|
|
24
22
|
alias start sg unless method_defined?(:start)
|
|
25
23
|
|
|
26
|
-
#
|
|
27
|
-
# object
|
|
24
|
+
# Methods <tt>DateTime#as_json</tt> and +DateTime.json_create+ may be used
|
|
25
|
+
# to serialize and deserialize a \DateTime object;
|
|
26
|
+
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
|
27
|
+
#
|
|
28
|
+
# \Method <tt>DateTime#as_json</tt> serializes +self+,
|
|
29
|
+
# returning a 2-element hash representing +self+:
|
|
30
|
+
#
|
|
31
|
+
# require 'json/add/datetime'
|
|
32
|
+
# x = DateTime.now.as_json
|
|
33
|
+
# # => {"json_class"=>"DateTime", "y"=>2023, "m"=>11, "d"=>21, "sg"=>2299161.0}
|
|
34
|
+
#
|
|
35
|
+
# \Method +JSON.create+ deserializes such a hash, returning a \DateTime object:
|
|
36
|
+
#
|
|
37
|
+
# DateTime.json_create(x) # BUG? Raises Date::Error "invalid date"
|
|
38
|
+
#
|
|
28
39
|
def as_json(*)
|
|
29
40
|
{
|
|
30
41
|
JSON.create_id => self.class.name,
|
|
@@ -39,9 +50,15 @@ class DateTime
|
|
|
39
50
|
}
|
|
40
51
|
end
|
|
41
52
|
|
|
42
|
-
#
|
|
43
|
-
#
|
|
44
|
-
#
|
|
53
|
+
# Returns a JSON string representing +self+:
|
|
54
|
+
#
|
|
55
|
+
# require 'json/add/datetime'
|
|
56
|
+
# puts DateTime.now.to_json
|
|
57
|
+
#
|
|
58
|
+
# Output:
|
|
59
|
+
#
|
|
60
|
+
# {"json_class":"DateTime","y":2023,"m":11,"d":21,"sg":2299161.0}
|
|
61
|
+
#
|
|
45
62
|
def to_json(*args)
|
|
46
63
|
as_json.to_json(*args)
|
|
47
64
|
end
|
data/lib/json/add/exception.rb
CHANGED
|
@@ -5,16 +5,27 @@ end
|
|
|
5
5
|
|
|
6
6
|
class Exception
|
|
7
7
|
|
|
8
|
-
#
|
|
9
|
-
# <tt>m</tt> and backtrace <tt>b</tt> serialized with <tt>to_json</tt>
|
|
8
|
+
# See #as_json.
|
|
10
9
|
def self.json_create(object)
|
|
11
10
|
result = new(object['m'])
|
|
12
11
|
result.set_backtrace object['b']
|
|
13
12
|
result
|
|
14
13
|
end
|
|
15
14
|
|
|
16
|
-
#
|
|
17
|
-
# object
|
|
15
|
+
# Methods <tt>Exception#as_json</tt> and +Exception.json_create+ may be used
|
|
16
|
+
# to serialize and deserialize a \Exception object;
|
|
17
|
+
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
|
18
|
+
#
|
|
19
|
+
# \Method <tt>Exception#as_json</tt> serializes +self+,
|
|
20
|
+
# returning a 2-element hash representing +self+:
|
|
21
|
+
#
|
|
22
|
+
# require 'json/add/exception'
|
|
23
|
+
# x = Exception.new('Foo').as_json # => {"json_class"=>"Exception", "m"=>"Foo", "b"=>nil}
|
|
24
|
+
#
|
|
25
|
+
# \Method +JSON.create+ deserializes such a hash, returning a \Exception object:
|
|
26
|
+
#
|
|
27
|
+
# Exception.json_create(x) # => #<Exception: Foo>
|
|
28
|
+
#
|
|
18
29
|
def as_json(*)
|
|
19
30
|
{
|
|
20
31
|
JSON.create_id => self.class.name,
|
|
@@ -23,8 +34,15 @@ class Exception
|
|
|
23
34
|
}
|
|
24
35
|
end
|
|
25
36
|
|
|
26
|
-
#
|
|
27
|
-
#
|
|
37
|
+
# Returns a JSON string representing +self+:
|
|
38
|
+
#
|
|
39
|
+
# require 'json/add/exception'
|
|
40
|
+
# puts Exception.new('Foo').to_json
|
|
41
|
+
#
|
|
42
|
+
# Output:
|
|
43
|
+
#
|
|
44
|
+
# {"json_class":"Exception","m":"Foo","b":null}
|
|
45
|
+
#
|
|
28
46
|
def to_json(*args)
|
|
29
47
|
as_json.to_json(*args)
|
|
30
48
|
end
|
data/lib/json/add/ostruct.rb
CHANGED
|
@@ -2,18 +2,34 @@
|
|
|
2
2
|
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
|
3
3
|
require 'json'
|
|
4
4
|
end
|
|
5
|
-
|
|
5
|
+
begin
|
|
6
|
+
require 'ostruct'
|
|
7
|
+
rescue LoadError
|
|
8
|
+
end
|
|
6
9
|
|
|
7
10
|
class OpenStruct
|
|
8
11
|
|
|
9
|
-
#
|
|
10
|
-
# <tt>t</tt> serialized by <tt>to_json</tt>.
|
|
12
|
+
# See #as_json.
|
|
11
13
|
def self.json_create(object)
|
|
12
14
|
new(object['t'] || object[:t])
|
|
13
15
|
end
|
|
14
16
|
|
|
15
|
-
#
|
|
16
|
-
# object
|
|
17
|
+
# Methods <tt>OpenStruct#as_json</tt> and +OpenStruct.json_create+ may be used
|
|
18
|
+
# to serialize and deserialize a \OpenStruct object;
|
|
19
|
+
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
|
20
|
+
#
|
|
21
|
+
# \Method <tt>OpenStruct#as_json</tt> serializes +self+,
|
|
22
|
+
# returning a 2-element hash representing +self+:
|
|
23
|
+
#
|
|
24
|
+
# require 'json/add/ostruct'
|
|
25
|
+
# x = OpenStruct.new('name' => 'Rowdy', :age => nil).as_json
|
|
26
|
+
# # => {"json_class"=>"OpenStruct", "t"=>{:name=>'Rowdy', :age=>nil}}
|
|
27
|
+
#
|
|
28
|
+
# \Method +JSON.create+ deserializes such a hash, returning a \OpenStruct object:
|
|
29
|
+
#
|
|
30
|
+
# OpenStruct.json_create(x)
|
|
31
|
+
# # => #<OpenStruct name='Rowdy', age=nil>
|
|
32
|
+
#
|
|
17
33
|
def as_json(*)
|
|
18
34
|
klass = self.class.name
|
|
19
35
|
klass.to_s.empty? and raise JSON::JSONError, "Only named structs are supported!"
|
|
@@ -23,9 +39,16 @@ class OpenStruct
|
|
|
23
39
|
}
|
|
24
40
|
end
|
|
25
41
|
|
|
26
|
-
#
|
|
27
|
-
#
|
|
42
|
+
# Returns a JSON string representing +self+:
|
|
43
|
+
#
|
|
44
|
+
# require 'json/add/ostruct'
|
|
45
|
+
# puts OpenStruct.new('name' => 'Rowdy', :age => nil).to_json
|
|
46
|
+
#
|
|
47
|
+
# Output:
|
|
48
|
+
#
|
|
49
|
+
# {"json_class":"OpenStruct","t":{'name':'Rowdy',"age":null}}
|
|
50
|
+
#
|
|
28
51
|
def to_json(*args)
|
|
29
52
|
as_json.to_json(*args)
|
|
30
53
|
end
|
|
31
|
-
end
|
|
54
|
+
end if defined?(::OpenStruct)
|
data/lib/json/add/range.rb
CHANGED
|
@@ -5,24 +5,28 @@ end
|
|
|
5
5
|
|
|
6
6
|
class Range
|
|
7
7
|
|
|
8
|
-
#
|
|
9
|
-
# which must be an array of values suitable for a call to Range.new:
|
|
10
|
-
#
|
|
11
|
-
# require 'json/add/range'
|
|
12
|
-
# Range.json_create({"a"=>[1, 4]}) # => 1..4
|
|
13
|
-
# Range.json_create({"a"=>[1, 4, true]}) # => 1...4
|
|
14
|
-
# Range.json_create({"a" => ['a', 'd']}) # => "a".."d"
|
|
15
|
-
#
|
|
8
|
+
# See #as_json.
|
|
16
9
|
def self.json_create(object)
|
|
17
10
|
new(*object['a'])
|
|
18
11
|
end
|
|
19
12
|
|
|
20
|
-
#
|
|
13
|
+
# Methods <tt>Range#as_json</tt> and +Range.json_create+ may be used
|
|
14
|
+
# to serialize and deserialize a \Range object;
|
|
15
|
+
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
|
16
|
+
#
|
|
17
|
+
# \Method <tt>Range#as_json</tt> serializes +self+,
|
|
18
|
+
# returning a 2-element hash representing +self+:
|
|
21
19
|
#
|
|
22
20
|
# require 'json/add/range'
|
|
23
|
-
# (1..4).as_json # => {"json_class"=>"Range", "a"=>[1, 4, false]}
|
|
24
|
-
# (1...4).as_json # => {"json_class"=>"Range", "a"=>[1, 4, true]}
|
|
25
|
-
# ('a'..'d').as_json # => {"json_class"=>"Range", "a"=>["a", "d", false]}
|
|
21
|
+
# x = (1..4).as_json # => {"json_class"=>"Range", "a"=>[1, 4, false]}
|
|
22
|
+
# y = (1...4).as_json # => {"json_class"=>"Range", "a"=>[1, 4, true]}
|
|
23
|
+
# z = ('a'..'d').as_json # => {"json_class"=>"Range", "a"=>["a", "d", false]}
|
|
24
|
+
#
|
|
25
|
+
# \Method +JSON.create+ deserializes such a hash, returning a \Range object:
|
|
26
|
+
#
|
|
27
|
+
# Range.json_create(x) # => 1..4
|
|
28
|
+
# Range.json_create(y) # => 1...4
|
|
29
|
+
# Range.json_create(z) # => "a".."d"
|
|
26
30
|
#
|
|
27
31
|
def as_json(*)
|
|
28
32
|
{
|
|
@@ -34,9 +38,15 @@ class Range
|
|
|
34
38
|
# Returns a JSON string representing +self+:
|
|
35
39
|
#
|
|
36
40
|
# require 'json/add/range'
|
|
37
|
-
# (1..4).to_json
|
|
38
|
-
# (1...4).to_json
|
|
39
|
-
# ('a'..'d').to_json
|
|
41
|
+
# puts (1..4).to_json
|
|
42
|
+
# puts (1...4).to_json
|
|
43
|
+
# puts ('a'..'d').to_json
|
|
44
|
+
#
|
|
45
|
+
# Output:
|
|
46
|
+
#
|
|
47
|
+
# {"json_class":"Range","a":[1,4,false]}
|
|
48
|
+
# {"json_class":"Range","a":[1,4,true]}
|
|
49
|
+
# {"json_class":"Range","a":["a","d",false]}
|
|
40
50
|
#
|
|
41
51
|
def to_json(*args)
|
|
42
52
|
as_json.to_json(*args)
|
data/lib/json/add/rational.rb
CHANGED
|
@@ -4,14 +4,28 @@ unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
|
|
4
4
|
end
|
|
5
5
|
|
|
6
6
|
class Rational
|
|
7
|
-
|
|
8
|
-
#
|
|
7
|
+
|
|
8
|
+
# See #as_json.
|
|
9
9
|
def self.json_create(object)
|
|
10
10
|
Rational(object['n'], object['d'])
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
#
|
|
14
|
-
# object
|
|
13
|
+
# Methods <tt>Rational#as_json</tt> and +Rational.json_create+ may be used
|
|
14
|
+
# to serialize and deserialize a \Rational object;
|
|
15
|
+
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
|
16
|
+
#
|
|
17
|
+
# \Method <tt>Rational#as_json</tt> serializes +self+,
|
|
18
|
+
# returning a 2-element hash representing +self+:
|
|
19
|
+
#
|
|
20
|
+
# require 'json/add/rational'
|
|
21
|
+
# x = Rational(2, 3).as_json
|
|
22
|
+
# # => {"json_class"=>"Rational", "n"=>2, "d"=>3}
|
|
23
|
+
#
|
|
24
|
+
# \Method +JSON.create+ deserializes such a hash, returning a \Rational object:
|
|
25
|
+
#
|
|
26
|
+
# Rational.json_create(x)
|
|
27
|
+
# # => (2/3)
|
|
28
|
+
#
|
|
15
29
|
def as_json(*)
|
|
16
30
|
{
|
|
17
31
|
JSON.create_id => self.class.name,
|
|
@@ -20,7 +34,15 @@ class Rational
|
|
|
20
34
|
}
|
|
21
35
|
end
|
|
22
36
|
|
|
23
|
-
#
|
|
37
|
+
# Returns a JSON string representing +self+:
|
|
38
|
+
#
|
|
39
|
+
# require 'json/add/rational'
|
|
40
|
+
# puts Rational(2, 3).to_json
|
|
41
|
+
#
|
|
42
|
+
# Output:
|
|
43
|
+
#
|
|
44
|
+
# {"json_class":"Rational","n":2,"d":3}
|
|
45
|
+
#
|
|
24
46
|
def to_json(*args)
|
|
25
47
|
as_json.to_json(*args)
|
|
26
48
|
end
|
data/lib/json/add/regexp.rb
CHANGED
|
@@ -5,15 +5,26 @@ end
|
|
|
5
5
|
|
|
6
6
|
class Regexp
|
|
7
7
|
|
|
8
|
-
#
|
|
9
|
-
# <tt>s</tt> (Regexp or String) and options <tt>o</tt> serialized by
|
|
10
|
-
# <tt>to_json</tt>
|
|
8
|
+
# See #as_json.
|
|
11
9
|
def self.json_create(object)
|
|
12
10
|
new(object['s'], object['o'])
|
|
13
11
|
end
|
|
14
12
|
|
|
15
|
-
#
|
|
16
|
-
# object
|
|
13
|
+
# Methods <tt>Regexp#as_json</tt> and +Regexp.json_create+ may be used
|
|
14
|
+
# to serialize and deserialize a \Regexp object;
|
|
15
|
+
# see Marshal[https://docs.ruby-lang.org/en/master/Marshal.html].
|
|
16
|
+
#
|
|
17
|
+
# \Method <tt>Regexp#as_json</tt> serializes +self+,
|
|
18
|
+
# returning a 2-element hash representing +self+:
|
|
19
|
+
#
|
|
20
|
+
# require 'json/add/regexp'
|
|
21
|
+
# x = /foo/.as_json
|
|
22
|
+
# # => {"json_class"=>"Regexp", "o"=>0, "s"=>"foo"}
|
|
23
|
+
#
|
|
24
|
+
# \Method +JSON.create+ deserializes such a hash, returning a \Regexp object:
|
|
25
|
+
#
|
|
26
|
+
# Regexp.json_create(x) # => /foo/
|
|
27
|
+
#
|
|
17
28
|
def as_json(*)
|
|
18
29
|
{
|
|
19
30
|
JSON.create_id => self.class.name,
|
|
@@ -22,8 +33,15 @@ class Regexp
|
|
|
22
33
|
}
|
|
23
34
|
end
|
|
24
35
|
|
|
25
|
-
#
|
|
26
|
-
#
|
|
36
|
+
# Returns a JSON string representing +self+:
|
|
37
|
+
#
|
|
38
|
+
# require 'json/add/regexp'
|
|
39
|
+
# puts /foo/.to_json
|
|
40
|
+
#
|
|
41
|
+
# Output:
|
|
42
|
+
#
|
|
43
|
+
# {"json_class":"Regexp","o":0,"s":"foo"}
|
|
44
|
+
#
|
|
27
45
|
def to_json(*args)
|
|
28
46
|
as_json.to_json(*args)
|
|
29
47
|
end
|
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
|
@@ -5,14 +5,28 @@ 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,26 @@
|
|
|
1
|
+
|
|
1
2
|
#frozen_string_literal: false
|
|
2
3
|
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
|
3
4
|
require 'json'
|
|
4
5
|
end
|
|
5
6
|
|
|
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
|
@@ -5,7 +5,7 @@ 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
|
|
@@ -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
|
data/lib/json/common.rb
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#frozen_string_literal: false
|
|
2
2
|
require 'json/version'
|
|
3
|
-
require 'json/generic_object'
|
|
4
3
|
|
|
5
4
|
module JSON
|
|
5
|
+
autoload :GenericObject, 'json/generic_object'
|
|
6
|
+
|
|
6
7
|
NOT_SET = Object.new.freeze
|
|
7
8
|
private_constant :NOT_SET
|
|
8
9
|
|
|
@@ -611,17 +612,18 @@ module JSON
|
|
|
611
612
|
# puts File.read(path)
|
|
612
613
|
# Output:
|
|
613
614
|
# {"foo":[0,1],"bar":{"baz":2,"bat":3},"bam":"bad"}
|
|
614
|
-
def dump(obj, anIO = nil, limit = nil,
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
615
|
+
def dump(obj, anIO = nil, limit = nil, kwargs = nil)
|
|
616
|
+
io_limit_opt = [anIO, limit, kwargs].compact
|
|
617
|
+
kwargs = io_limit_opt.pop if io_limit_opt.last.is_a?(Hash)
|
|
618
|
+
anIO, limit = io_limit_opt
|
|
619
|
+
if anIO.respond_to?(:to_io)
|
|
620
|
+
anIO = anIO.to_io
|
|
621
|
+
elsif limit.nil? && !anIO.respond_to?(:write)
|
|
622
|
+
anIO, limit = nil, anIO
|
|
621
623
|
end
|
|
622
624
|
opts = JSON.dump_default_options
|
|
623
625
|
opts = opts.merge(:max_nesting => limit) if limit
|
|
624
|
-
opts
|
|
626
|
+
opts = merge_dump_options(opts, **kwargs) if kwargs
|
|
625
627
|
result = generate(obj, opts)
|
|
626
628
|
if anIO
|
|
627
629
|
anIO.write result
|
|
@@ -637,6 +639,15 @@ module JSON
|
|
|
637
639
|
def self.iconv(to, from, string)
|
|
638
640
|
string.encode(to, from)
|
|
639
641
|
end
|
|
642
|
+
|
|
643
|
+
def merge_dump_options(opts, strict: NOT_SET)
|
|
644
|
+
opts = opts.merge(strict: strict) if NOT_SET != strict
|
|
645
|
+
opts
|
|
646
|
+
end
|
|
647
|
+
|
|
648
|
+
class << self
|
|
649
|
+
private :merge_dump_options
|
|
650
|
+
end
|
|
640
651
|
end
|
|
641
652
|
|
|
642
653
|
module ::Kernel
|
data/lib/json/ext/generator.jar
CHANGED
|
Binary file
|
data/lib/json/ext/parser.jar
CHANGED
|
Binary file
|
data/lib/json/generic_object.rb
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
#frozen_string_literal: false
|
|
2
|
-
|
|
2
|
+
begin
|
|
3
|
+
require 'ostruct'
|
|
4
|
+
rescue LoadError
|
|
5
|
+
warn "JSON::GenericObject requires 'ostruct'. Please install it with `gem install ostruct`."
|
|
6
|
+
end
|
|
3
7
|
|
|
4
8
|
module JSON
|
|
5
9
|
class GenericObject < OpenStruct
|
|
@@ -67,5 +71,5 @@ module JSON
|
|
|
67
71
|
def to_json(*a)
|
|
68
72
|
as_json.to_json(*a)
|
|
69
73
|
end
|
|
70
|
-
end
|
|
74
|
+
end if defined?(::OpenStruct)
|
|
71
75
|
end
|
data/lib/json/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: json
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.7.
|
|
4
|
+
version: 2.7.2
|
|
5
5
|
platform: java
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel Luz
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2024-04-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A JSON implementation as a JRuby extension.
|
|
14
14
|
email: dev+ruby@mernen.com
|