json 1.8.6-java → 2.11.1-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.
Files changed (74) hide show
  1. checksums.yaml +5 -5
  2. data/BSDL +22 -0
  3. data/CHANGES.md +619 -0
  4. data/COPYING +56 -0
  5. data/LEGAL +8 -0
  6. data/README.md +268 -0
  7. data/json.gemspec +63 -0
  8. data/lib/json/add/bigdecimal.rb +41 -11
  9. data/lib/json/add/complex.rb +32 -9
  10. data/lib/json/add/core.rb +1 -0
  11. data/lib/json/add/date.rb +27 -7
  12. data/lib/json/add/date_time.rb +26 -9
  13. data/lib/json/add/exception.rb +25 -7
  14. data/lib/json/add/ostruct.rb +32 -9
  15. data/lib/json/add/range.rb +33 -8
  16. data/lib/json/add/rational.rb +30 -8
  17. data/lib/json/add/regexp.rb +28 -10
  18. data/lib/json/add/set.rb +48 -0
  19. data/lib/json/add/struct.rb +29 -7
  20. data/lib/json/add/symbol.rb +34 -7
  21. data/lib/json/add/time.rb +29 -15
  22. data/lib/json/common.rb +916 -316
  23. data/lib/json/ext/generator/state.rb +106 -0
  24. data/lib/json/ext/generator.jar +0 -0
  25. data/lib/json/ext/parser.jar +0 -0
  26. data/lib/json/ext.rb +34 -10
  27. data/lib/json/generic_object.rb +11 -6
  28. data/lib/json/truffle_ruby/generator.rb +690 -0
  29. data/lib/json/version.rb +3 -6
  30. data/lib/json.rb +560 -35
  31. metadata +29 -82
  32. data/lib/json/pure/generator.rb +0 -530
  33. data/lib/json/pure/parser.rb +0 -359
  34. data/lib/json/pure.rb +0 -21
  35. data/tests/fixtures/fail1.json +0 -1
  36. data/tests/fixtures/fail10.json +0 -1
  37. data/tests/fixtures/fail11.json +0 -1
  38. data/tests/fixtures/fail12.json +0 -1
  39. data/tests/fixtures/fail13.json +0 -1
  40. data/tests/fixtures/fail14.json +0 -1
  41. data/tests/fixtures/fail18.json +0 -1
  42. data/tests/fixtures/fail19.json +0 -1
  43. data/tests/fixtures/fail2.json +0 -1
  44. data/tests/fixtures/fail20.json +0 -1
  45. data/tests/fixtures/fail21.json +0 -1
  46. data/tests/fixtures/fail22.json +0 -1
  47. data/tests/fixtures/fail23.json +0 -1
  48. data/tests/fixtures/fail24.json +0 -1
  49. data/tests/fixtures/fail25.json +0 -1
  50. data/tests/fixtures/fail27.json +0 -2
  51. data/tests/fixtures/fail28.json +0 -2
  52. data/tests/fixtures/fail3.json +0 -1
  53. data/tests/fixtures/fail4.json +0 -1
  54. data/tests/fixtures/fail5.json +0 -1
  55. data/tests/fixtures/fail6.json +0 -1
  56. data/tests/fixtures/fail7.json +0 -1
  57. data/tests/fixtures/fail8.json +0 -1
  58. data/tests/fixtures/fail9.json +0 -1
  59. data/tests/fixtures/pass1.json +0 -56
  60. data/tests/fixtures/pass15.json +0 -1
  61. data/tests/fixtures/pass16.json +0 -1
  62. data/tests/fixtures/pass17.json +0 -1
  63. data/tests/fixtures/pass2.json +0 -1
  64. data/tests/fixtures/pass26.json +0 -1
  65. data/tests/fixtures/pass3.json +0 -6
  66. data/tests/setup_variant.rb +0 -11
  67. data/tests/test_json.rb +0 -519
  68. data/tests/test_json_addition.rb +0 -196
  69. data/tests/test_json_encoding.rb +0 -65
  70. data/tests/test_json_fixtures.rb +0 -35
  71. data/tests/test_json_generate.rb +0 -348
  72. data/tests/test_json_generic_object.rb +0 -75
  73. data/tests/test_json_string_matching.rb +0 -39
  74. data/tests/test_json_unicode.rb +0 -72
@@ -1,20 +1,31 @@
1
+ # frozen_string_literal: true
1
2
  unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
2
3
  require 'json'
3
4
  end
4
5
 
5
- # Exception serialization/deserialization
6
6
  class Exception
7
7
 
8
- # Deserializes JSON string by constructing new Exception object with message
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
- # Returns a hash, that will be turned into a JSON object and represent this
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
- # Stores class name (Exception) with message <tt>m</tt> and backtrace array
27
- # <tt>b</tt> as JSON string
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
@@ -1,19 +1,35 @@
1
+ # frozen_string_literal: true
1
2
  unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
2
3
  require 'json'
3
4
  end
4
- require 'ostruct'
5
+ begin
6
+ require 'ostruct'
7
+ rescue LoadError
8
+ end
5
9
 
6
- # OpenStruct serialization/deserialization
7
10
  class OpenStruct
8
11
 
9
- # Deserializes JSON string by constructing new Struct object with values
10
- # <tt>v</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
- # Returns a hash, that will be turned into a JSON object and represent this
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
- # Stores class name (OpenStruct) with this struct's values <tt>v</tt> as a
27
- # JSON string.
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)
@@ -1,18 +1,33 @@
1
+ # frozen_string_literal: true
1
2
  unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
2
3
  require 'json'
3
4
  end
4
5
 
5
- # Range serialization/deserialization
6
6
  class Range
7
7
 
8
- # Deserializes JSON string by constructing new Range object with arguments
9
- # <tt>a</tt> serialized by <tt>to_json</tt>.
8
+ # See #as_json.
10
9
  def self.json_create(object)
11
10
  new(*object['a'])
12
11
  end
13
12
 
14
- # Returns a hash, that will be turned into a JSON object and represent this
15
- # object.
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+:
19
+ #
20
+ # require 'json/add/range'
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"
30
+ #
16
31
  def as_json(*)
17
32
  {
18
33
  JSON.create_id => self.class.name,
@@ -20,9 +35,19 @@ class Range
20
35
  }
21
36
  end
22
37
 
23
- # Stores class name (Range) with JSON array of arguments <tt>a</tt> which
24
- # include <tt>first</tt> (integer), <tt>last</tt> (integer), and
25
- # <tt>exclude_end?</tt> (boolean) as JSON string.
38
+ # Returns a JSON string representing +self+:
39
+ #
40
+ # require 'json/add/range'
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]}
50
+ #
26
51
  def to_json(*args)
27
52
  as_json.to_json(*args)
28
53
  end
@@ -1,17 +1,31 @@
1
+ # frozen_string_literal: true
1
2
  unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
2
3
  require 'json'
3
4
  end
4
- defined?(::Rational) or require 'rational'
5
5
 
6
6
  class Rational
7
- # Deserializes JSON string by converting numerator value <tt>n</tt>,
8
- # denominator value <tt>d</tt>, to a Rational object.
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
- # Returns a hash, that will be turned into a JSON object and represent this
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,8 +34,16 @@ class Rational
20
34
  }
21
35
  end
22
36
 
23
- # Stores class name (Rational) along with numerator value <tt>n</tt> and denominator value <tt>d</tt> as JSON string
24
- def to_json(*)
25
- as_json.to_json
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
+ #
46
+ def to_json(*args)
47
+ as_json.to_json(*args)
26
48
  end
27
49
  end
@@ -1,19 +1,30 @@
1
+ # frozen_string_literal: true
1
2
  unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
2
3
  require 'json'
3
4
  end
4
5
 
5
- # Regexp serialization/deserialization
6
6
  class Regexp
7
7
 
8
- # Deserializes JSON string by constructing new Regexp object with source
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
- # Returns a hash, that will be turned into a JSON object and represent this
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,9 +33,16 @@ class Regexp
22
33
  }
23
34
  end
24
35
 
25
- # Stores class name (Regexp) with options <tt>o</tt> and source <tt>s</tt>
26
- # (Regexp or String) as JSON string
27
- def to_json(*)
28
- as_json.to_json
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
+ #
45
+ def to_json(*args)
46
+ as_json.to_json(*args)
29
47
  end
30
48
  end
@@ -0,0 +1,48 @@
1
+ unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
2
+ require 'json'
3
+ end
4
+ defined?(::Set) or require 'set'
5
+
6
+ class Set
7
+
8
+ # See #as_json.
9
+ def self.json_create(object)
10
+ new object['a']
11
+ end
12
+
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"}>
27
+ #
28
+ def as_json(*)
29
+ {
30
+ JSON.create_id => self.class.name,
31
+ 'a' => to_a,
32
+ }
33
+ end
34
+
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
+ #
44
+ def to_json(*args)
45
+ as_json.to_json(*args)
46
+ end
47
+ end
48
+
@@ -1,18 +1,32 @@
1
+ # frozen_string_literal: true
1
2
  unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
2
3
  require 'json'
3
4
  end
4
5
 
5
- # Struct serialization/deserialization
6
6
  class Struct
7
7
 
8
- # Deserializes JSON string by constructing new Struct object with values
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
- # Returns a hash, that will be turned into a JSON object and represent this
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
- # Stores class name (Struct) with Struct values <tt>v</tt> as a JSON string.
26
- # Only named structs are supported.
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
@@ -1,11 +1,25 @@
1
+ # frozen_string_literal: true
1
2
  unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
2
3
  require 'json'
3
4
  end
4
5
 
5
- # Symbol serialization/deserialization
6
6
  class Symbol
7
- # Returns a hash, that will be turned into a JSON object and represent this
8
- # object.
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
- # Stores class name (Symbol) with String representation of Symbol as a JSON string.
17
- def to_json(*a)
18
- as_json.to_json(*a)
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
- # Deserializes JSON string by converting the <tt>string</tt> value stored in the object to a Symbol
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: true
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
- # Deserializes JSON string by converting time since epoch to Time
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
- if method_defined?(:tv_nsec)
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
- # Returns a hash, that will be turned into a JSON object and represent this
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' => nanoseconds,
36
+ 'n' => tv_nsec,
30
37
  }
31
38
  end
32
39
 
33
- # Stores class name (Time) with number of seconds since epoch and number of
34
- # microseconds for Time as JSON string
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