oj 3.11.5 → 3.16.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1421 -0
- data/README.md +19 -5
- data/RELEASE_NOTES.md +61 -0
- data/ext/oj/buf.h +20 -6
- data/ext/oj/cache.c +329 -0
- data/ext/oj/cache.h +22 -0
- data/ext/oj/cache8.c +10 -9
- data/ext/oj/circarray.c +8 -6
- data/ext/oj/circarray.h +2 -2
- data/ext/oj/code.c +19 -33
- data/ext/oj/code.h +2 -2
- data/ext/oj/compat.c +27 -77
- data/ext/oj/custom.c +86 -179
- data/ext/oj/debug.c +126 -0
- data/ext/oj/dump.c +256 -249
- data/ext/oj/dump.h +26 -12
- data/ext/oj/dump_compat.c +565 -642
- data/ext/oj/dump_leaf.c +17 -63
- data/ext/oj/dump_object.c +65 -187
- data/ext/oj/dump_strict.c +27 -51
- data/ext/oj/encoder.c +43 -0
- data/ext/oj/err.c +2 -13
- data/ext/oj/err.h +24 -8
- data/ext/oj/extconf.rb +21 -6
- data/ext/oj/fast.c +149 -149
- data/ext/oj/intern.c +313 -0
- data/ext/oj/intern.h +22 -0
- data/ext/oj/mem.c +318 -0
- data/ext/oj/mem.h +53 -0
- data/ext/oj/mimic_json.c +121 -106
- data/ext/oj/object.c +85 -162
- data/ext/oj/odd.c +89 -67
- data/ext/oj/odd.h +15 -15
- data/ext/oj/oj.c +542 -411
- data/ext/oj/oj.h +99 -73
- data/ext/oj/parse.c +175 -187
- data/ext/oj/parse.h +26 -24
- data/ext/oj/parser.c +1600 -0
- data/ext/oj/parser.h +101 -0
- data/ext/oj/rails.c +112 -159
- data/ext/oj/rails.h +1 -1
- data/ext/oj/reader.c +11 -14
- data/ext/oj/reader.h +4 -2
- data/ext/oj/resolve.c +5 -24
- data/ext/oj/rxclass.c +7 -6
- data/ext/oj/rxclass.h +1 -1
- data/ext/oj/saj.c +22 -33
- data/ext/oj/saj2.c +584 -0
- data/ext/oj/saj2.h +23 -0
- data/ext/oj/scp.c +5 -28
- data/ext/oj/sparse.c +28 -72
- data/ext/oj/stream_writer.c +50 -40
- data/ext/oj/strict.c +56 -61
- data/ext/oj/string_writer.c +72 -39
- data/ext/oj/trace.h +31 -4
- data/ext/oj/usual.c +1218 -0
- data/ext/oj/usual.h +69 -0
- data/ext/oj/util.h +1 -1
- data/ext/oj/val_stack.c +14 -3
- data/ext/oj/val_stack.h +8 -7
- data/ext/oj/validate.c +46 -0
- data/ext/oj/wab.c +63 -88
- data/lib/oj/active_support_helper.rb +1 -3
- data/lib/oj/bag.rb +7 -1
- data/lib/oj/easy_hash.rb +4 -5
- data/lib/oj/error.rb +1 -2
- data/lib/oj/json.rb +162 -150
- data/lib/oj/mimic.rb +9 -7
- data/lib/oj/saj.rb +20 -6
- data/lib/oj/schandler.rb +5 -4
- data/lib/oj/state.rb +12 -8
- data/lib/oj/version.rb +1 -2
- data/lib/oj.rb +2 -0
- data/pages/Compatibility.md +1 -1
- data/pages/InstallOptions.md +20 -0
- data/pages/JsonGem.md +15 -0
- data/pages/Modes.md +8 -3
- data/pages/Options.md +43 -5
- data/pages/Parser.md +309 -0
- data/pages/Rails.md +14 -2
- data/test/_test_active.rb +8 -9
- data/test/_test_active_mimic.rb +7 -8
- data/test/_test_mimic_rails.rb +17 -20
- data/test/activerecord/result_test.rb +5 -6
- data/test/activesupport6/encoding_test.rb +63 -28
- data/test/{activesupport5 → activesupport7}/abstract_unit.rb +16 -12
- data/test/{activesupport5 → activesupport7}/decoding_test.rb +2 -10
- data/test/{activesupport5 → activesupport7}/encoding_test.rb +86 -50
- data/test/{activesupport5 → activesupport7}/encoding_test_cases.rb +6 -0
- data/test/{activesupport5 → activesupport7}/time_zone_test_helpers.rb +8 -0
- data/test/files.rb +15 -15
- data/test/foo.rb +16 -45
- data/test/helper.rb +11 -8
- data/test/isolated/shared.rb +3 -2
- data/test/json_gem/json_addition_test.rb +2 -2
- data/test/json_gem/json_common_interface_test.rb +8 -6
- data/test/json_gem/json_encoding_test.rb +0 -0
- data/test/json_gem/json_ext_parser_test.rb +1 -0
- data/test/json_gem/json_fixtures_test.rb +3 -2
- data/test/json_gem/json_generator_test.rb +56 -38
- data/test/json_gem/json_generic_object_test.rb +11 -11
- data/test/json_gem/json_parser_test.rb +54 -47
- data/test/json_gem/json_string_matching_test.rb +9 -9
- data/test/json_gem/test_helper.rb +7 -3
- data/test/mem.rb +34 -0
- data/test/perf.rb +22 -27
- data/test/perf_compat.rb +31 -33
- data/test/perf_dump.rb +50 -0
- data/test/perf_fast.rb +80 -82
- data/test/perf_file.rb +27 -29
- data/test/perf_object.rb +65 -69
- data/test/perf_once.rb +59 -0
- data/test/perf_parser.rb +183 -0
- data/test/perf_saj.rb +46 -54
- data/test/perf_scp.rb +58 -69
- data/test/perf_simple.rb +41 -39
- data/test/perf_strict.rb +74 -82
- data/test/perf_wab.rb +67 -69
- data/test/prec.rb +5 -5
- data/test/sample/change.rb +0 -1
- data/test/sample/dir.rb +0 -1
- data/test/sample/doc.rb +0 -1
- data/test/sample/file.rb +0 -1
- data/test/sample/group.rb +0 -1
- data/test/sample/hasprops.rb +0 -1
- data/test/sample/layer.rb +0 -1
- data/test/sample/rect.rb +0 -1
- data/test/sample/shape.rb +0 -1
- data/test/sample/text.rb +0 -1
- data/test/sample.rb +16 -16
- data/test/sample_json.rb +8 -8
- data/test/test_compat.rb +95 -43
- data/test/test_custom.rb +73 -51
- data/test/test_debian.rb +7 -10
- data/test/test_fast.rb +135 -79
- data/test/test_file.rb +41 -30
- data/test/test_gc.rb +16 -5
- data/test/test_generate.rb +5 -5
- data/test/test_hash.rb +5 -5
- data/test/test_integer_range.rb +9 -9
- data/test/test_null.rb +20 -20
- data/test/test_object.rb +99 -96
- data/test/test_parser.rb +11 -0
- data/test/test_parser_debug.rb +27 -0
- data/test/test_parser_saj.rb +337 -0
- data/test/test_parser_usual.rb +251 -0
- data/test/test_rails.rb +2 -2
- data/test/test_saj.rb +10 -8
- data/test/test_scp.rb +37 -39
- data/test/test_strict.rb +40 -32
- data/test/test_various.rb +165 -84
- data/test/test_wab.rb +48 -44
- data/test/test_writer.rb +47 -47
- data/test/tests.rb +13 -5
- data/test/tests_mimic.rb +12 -3
- data/test/tests_mimic_addition.rb +12 -3
- metadata +74 -128
- data/ext/oj/hash.c +0 -131
- data/ext/oj/hash.h +0 -19
- data/ext/oj/hash_test.c +0 -491
- data/test/activesupport4/decoding_test.rb +0 -108
- data/test/activesupport4/encoding_test.rb +0 -531
- data/test/activesupport4/test_helper.rb +0 -41
- data/test/activesupport5/test_helper.rb +0 -72
- data/test/bar.rb +0 -35
- data/test/baz.rb +0 -16
- data/test/zoo.rb +0 -13
data/lib/oj/json.rb
CHANGED
@@ -1,176 +1,188 @@
|
|
1
|
-
|
2
1
|
require 'ostruct'
|
3
2
|
require 'oj/state'
|
4
3
|
|
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
|
-
|
4
|
+
if defined?(JSON::PRETTY_STATE_PROTOTYPE)
|
5
|
+
# There are enough people that try to use both the json gen and oj in mimic
|
6
|
+
# mode so don't display the warning.
|
7
|
+
|
8
|
+
# warn "WARNING: oj/json is a compatability shim used by Oj. Requiring the file explicitly is not recommended."
|
9
|
+
end
|
10
|
+
|
11
|
+
unless defined?(JSON::PRETTY_STATE_PROTOTYPE)
|
12
|
+
module JSON
|
13
|
+
NaN = 0.0/0.0 unless defined?(::JSON::NaN)
|
14
|
+
Infinity = 1.0/0.0 unless defined?(::JSON::Infinity)
|
15
|
+
MinusInfinity = -1.0/0.0 unless defined?(::JSON::MinusInfinity)
|
16
|
+
# Taken from the unit test. Note that items like check_circular? are not
|
17
|
+
# present.
|
18
|
+
PRETTY_STATE_PROTOTYPE = Ext::Generator::State.from_state({
|
19
|
+
:allow_nan => false,
|
20
|
+
:array_nl => "\n",
|
21
|
+
:ascii_only => false,
|
22
|
+
:buffer_initial_length => 1024,
|
23
|
+
:depth => 0,
|
24
|
+
:indent => " ",
|
25
|
+
:max_nesting => 100,
|
26
|
+
:object_nl => "\n",
|
27
|
+
:space => " ",
|
28
|
+
:space_before => "",
|
29
|
+
}) unless defined?(::JSON::PRETTY_STATE_PROTOTYPE)
|
30
|
+
SAFE_STATE_PROTOTYPE = Ext::Generator::State.from_state({
|
31
|
+
:allow_nan => false,
|
32
|
+
:array_nl => "",
|
33
|
+
:ascii_only => false,
|
34
|
+
:buffer_initial_length => 1024,
|
35
|
+
:depth => 0,
|
36
|
+
:indent => "",
|
37
|
+
:max_nesting => 100,
|
38
|
+
:object_nl => "",
|
39
|
+
:space => "",
|
40
|
+
:space_before => "",
|
41
|
+
}) unless defined?(::JSON::SAFE_STATE_PROTOTYPE)
|
42
|
+
FAST_STATE_PROTOTYPE = Ext::Generator::State.from_state({
|
43
|
+
:allow_nan => false,
|
44
|
+
:array_nl => "",
|
45
|
+
:ascii_only => false,
|
46
|
+
:buffer_initial_length => 1024,
|
47
|
+
:depth => 0,
|
48
|
+
:indent => "",
|
49
|
+
:max_nesting => 0,
|
50
|
+
:object_nl => "",
|
51
|
+
:space => "",
|
52
|
+
:space_before => "",
|
53
|
+
}) unless defined?(::JSON::FAST_STATE_PROTOTYPE)
|
54
|
+
|
55
|
+
def self.dump_default_options
|
56
|
+
Oj::MimicDumpOption.new
|
56
57
|
end
|
57
|
-
end
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
|
59
|
+
def self.dump_default_options=(h)
|
60
|
+
m = Oj::MimicDumpOption.new
|
61
|
+
h.each do |k, v|
|
62
|
+
m[k] = v
|
63
|
+
end
|
64
|
+
end
|
62
65
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
+
def self.parser=(p)
|
67
|
+
@@parser = p
|
68
|
+
end
|
66
69
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
+
def self.parser()
|
71
|
+
@@parser
|
72
|
+
end
|
70
73
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
+
def self.generator=(g)
|
75
|
+
@@generator = g
|
76
|
+
end
|
74
77
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
raise TypeError.new("already initialized") unless @source.nil?
|
79
|
-
@source = src
|
80
|
-
end
|
78
|
+
def self.generator()
|
79
|
+
@@generator
|
80
|
+
end
|
81
81
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
def parse()
|
88
|
-
raise TypeError.new("already initialized") if @source.nil?
|
89
|
-
JSON.parse(@source)
|
90
|
-
end
|
91
|
-
|
92
|
-
end # Parser
|
93
|
-
end # Ext
|
94
|
-
|
95
|
-
State = ::JSON::Ext::Generator::State unless defined?(::JSON::State)
|
96
|
-
|
97
|
-
begin
|
98
|
-
send(:remove_const, :Parser)
|
99
|
-
rescue
|
100
|
-
end
|
101
|
-
Parser = ::JSON::Ext::Parser unless defined?(::JSON::Parser)
|
102
|
-
self.parser = ::JSON::Ext::Parser
|
103
|
-
self.generator = ::JSON::Ext::Generator
|
104
|
-
|
105
|
-
# Taken directly from the json gem. Shamelessly copied. It is similar in
|
106
|
-
# some ways to the Oj::Bag class or the Oj::EasyHash class.
|
107
|
-
class GenericObject < OpenStruct
|
108
|
-
class << self
|
109
|
-
alias [] new
|
110
|
-
|
111
|
-
def json_creatable?
|
112
|
-
@json_creatable
|
113
|
-
end
|
82
|
+
module Ext
|
83
|
+
class Parser
|
84
|
+
def initialize(src)
|
85
|
+
raise TypeError.new("already initialized") unless @source.nil?
|
114
86
|
|
115
|
-
|
87
|
+
@source = src
|
88
|
+
end
|
116
89
|
|
117
|
-
|
118
|
-
|
119
|
-
data.delete JSON.create_id
|
120
|
-
self[data]
|
121
|
-
end
|
90
|
+
def source()
|
91
|
+
raise TypeError.new("already initialized") if @source.nil?
|
122
92
|
|
123
|
-
|
124
|
-
case
|
125
|
-
when object.respond_to?(:to_hash)
|
126
|
-
result = new
|
127
|
-
object.to_hash.each do |key, value|
|
128
|
-
result[key] = from_hash(value)
|
129
|
-
end
|
130
|
-
result
|
131
|
-
when object.respond_to?(:to_ary)
|
132
|
-
object.to_ary.map { |a| from_hash(a) }
|
133
|
-
else
|
134
|
-
object
|
93
|
+
@source
|
135
94
|
end
|
136
|
-
end
|
137
95
|
|
138
|
-
|
139
|
-
|
140
|
-
result.nil? ? new : result
|
141
|
-
end
|
96
|
+
def parse()
|
97
|
+
raise TypeError.new("already initialized") if @source.nil?
|
142
98
|
|
143
|
-
|
144
|
-
|
145
|
-
end
|
99
|
+
JSON.parse(@source)
|
100
|
+
end
|
146
101
|
|
147
|
-
|
102
|
+
end # Parser
|
103
|
+
end # Ext
|
148
104
|
|
149
|
-
|
105
|
+
State = ::JSON::Ext::Generator::State unless defined?(::JSON::State)
|
150
106
|
|
151
|
-
|
152
|
-
|
107
|
+
begin
|
108
|
+
send(:remove_const, :Parser)
|
109
|
+
rescue
|
110
|
+
# ignore and move on
|
153
111
|
end
|
112
|
+
Parser = ::JSON::Ext::Parser unless defined?(::JSON::Parser)
|
113
|
+
self.parser = ::JSON::Ext::Parser
|
114
|
+
self.generator = ::JSON::Ext::Generator
|
115
|
+
|
116
|
+
# Taken directly from the json gem. Shamelessly copied. It is similar in
|
117
|
+
# some ways to the Oj::Bag class or the Oj::EasyHash class.
|
118
|
+
class GenericObject < OpenStruct
|
119
|
+
class << self
|
120
|
+
alias [] new
|
121
|
+
|
122
|
+
def json_creatable?
|
123
|
+
@json_creatable
|
124
|
+
end
|
154
125
|
|
155
|
-
|
156
|
-
__send__(name)
|
157
|
-
end unless method_defined?(:[])
|
126
|
+
attr_writer :json_creatable
|
158
127
|
|
159
|
-
|
160
|
-
|
161
|
-
|
128
|
+
def json_create(data)
|
129
|
+
data = data.dup
|
130
|
+
data.delete JSON.create_id
|
131
|
+
self[data]
|
132
|
+
end
|
162
133
|
|
163
|
-
|
164
|
-
|
165
|
-
|
134
|
+
def from_hash(object)
|
135
|
+
case
|
136
|
+
when object.respond_to?(:to_hash)
|
137
|
+
result = new
|
138
|
+
object.to_hash.each do |key, value|
|
139
|
+
result[key] = from_hash(value)
|
140
|
+
end
|
141
|
+
result
|
142
|
+
when object.respond_to?(:to_ary)
|
143
|
+
object.to_ary.map { |a| from_hash(a) }
|
144
|
+
else
|
145
|
+
object
|
146
|
+
end
|
147
|
+
end
|
166
148
|
|
167
|
-
|
168
|
-
|
169
|
-
|
149
|
+
def load(source, proc = nil, opts = {})
|
150
|
+
result = ::JSON.load(source, proc, opts.merge(:object_class => self))
|
151
|
+
result.nil? ? new : result
|
152
|
+
end
|
170
153
|
|
171
|
-
|
172
|
-
|
154
|
+
def dump(obj, *args)
|
155
|
+
::JSON.dump(obj, *args)
|
156
|
+
end
|
157
|
+
|
158
|
+
end # self
|
159
|
+
|
160
|
+
self.json_creatable = false
|
161
|
+
|
162
|
+
def to_hash
|
163
|
+
table
|
164
|
+
end
|
165
|
+
|
166
|
+
def [](name)
|
167
|
+
__send__(name)
|
168
|
+
end unless method_defined?(:[])
|
169
|
+
|
170
|
+
def []=(name, value)
|
171
|
+
__send__("#{name}=", value)
|
172
|
+
end unless method_defined?(:[]=)
|
173
|
+
|
174
|
+
def |(other)
|
175
|
+
self.class[other.to_hash.merge(to_hash)]
|
176
|
+
end
|
177
|
+
|
178
|
+
def as_json(*)
|
179
|
+
{ JSON.create_id => self.class.name }.merge to_hash
|
180
|
+
end
|
181
|
+
|
182
|
+
def to_json(*a)
|
183
|
+
as_json.to_json(*a)
|
184
|
+
end
|
173
185
|
end
|
174
|
-
|
175
|
-
|
176
|
-
end
|
186
|
+
|
187
|
+
end # JSON
|
188
|
+
end
|
data/lib/oj/mimic.rb
CHANGED
@@ -1,10 +1,7 @@
|
|
1
|
+
# frozen_string_literal: false
|
1
2
|
|
2
3
|
require 'bigdecimal'
|
3
|
-
|
4
|
-
require 'ostruct'
|
5
|
-
rescue Exception
|
6
|
-
# ignore
|
7
|
-
end
|
4
|
+
require 'ostruct'
|
8
5
|
|
9
6
|
module Oj
|
10
7
|
|
@@ -23,6 +20,8 @@ module Oj
|
|
23
20
|
bigdecimal_load: :auto,
|
24
21
|
circular: false,
|
25
22
|
class_cache: false,
|
23
|
+
cache_keys: true,
|
24
|
+
cache_str: 5,
|
26
25
|
create_additions: false,
|
27
26
|
create_id: "json_class",
|
28
27
|
empty_string: false,
|
@@ -62,6 +61,8 @@ module Oj
|
|
62
61
|
self.store(:allow_nan, true)
|
63
62
|
self.store(:quirks_mode, oo[:quirks_mode])
|
64
63
|
self.store(:ascii_only, (:ascii == oo[:escape_mode]))
|
64
|
+
|
65
|
+
super
|
65
66
|
end
|
66
67
|
|
67
68
|
def []=(key, value)
|
@@ -100,6 +101,7 @@ module Oj
|
|
100
101
|
def as_json(*)
|
101
102
|
name = self.class.name.to_s
|
102
103
|
raise JSON::JSONError, "Only named structs are supported!" if 0 == name.length
|
104
|
+
|
103
105
|
{ JSON.create_id => name, 't' => table }
|
104
106
|
end
|
105
107
|
end
|
@@ -230,6 +232,7 @@ module Oj
|
|
230
232
|
def as_json(*)
|
231
233
|
name = self.class.name.to_s
|
232
234
|
raise JSON::JSONError, "Only named structs are supported!" if 0 == name.length
|
235
|
+
|
233
236
|
{ JSON.create_id => name, 'v' => values }
|
234
237
|
end
|
235
238
|
end
|
@@ -261,7 +264,7 @@ module Oj
|
|
261
264
|
end
|
262
265
|
end
|
263
266
|
def self.json_create(h)
|
264
|
-
if usec = h.delete('u')
|
267
|
+
if (usec = h.delete('u'))
|
265
268
|
h['n'] = usec * 1000
|
266
269
|
end
|
267
270
|
if instance_methods.include?(:tv_nsec)
|
@@ -271,7 +274,6 @@ module Oj
|
|
271
274
|
end
|
272
275
|
end
|
273
276
|
end
|
274
|
-
|
275
277
|
end # self.mimic_loaded
|
276
278
|
|
277
279
|
end # Oj
|
data/lib/oj/saj.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
module Oj
|
2
|
-
# A SAX style parse handler for JSON hence the acronym SAJ for Simple API
|
3
|
-
# JSON. The Oj::Saj handler class
|
4
|
-
# Oj::Saj key_parse() method
|
5
|
-
# is
|
2
|
+
# A SAX style parse handler for JSON hence the acronym SAJ for Simple API
|
3
|
+
# for JSON. The Oj::Saj handler class can be subclassed and then used with
|
4
|
+
# the Oj::Saj key_parse() method or with the more resent
|
5
|
+
# Oj::Parser.new(:saj). The Saj methods will then be called as the file is
|
6
|
+
# parsed.
|
7
|
+
#
|
8
|
+
# With Oj::Parser.new(:saj) each method can also include a line and column
|
9
|
+
# argument so hash_start(key) could also be hash_start(key, line,
|
10
|
+
# column). The error() method is no used with Oj::Parser.new(:saj) so it
|
11
|
+
# will never be called.
|
6
12
|
#
|
7
13
|
# @example
|
8
|
-
#
|
14
|
+
#
|
9
15
|
# require 'oj'
|
10
16
|
#
|
11
17
|
# class MySaj < ::Oj::Saj
|
@@ -23,6 +29,14 @@ module Oj
|
|
23
29
|
# Oj.saj_parse(cnt, f)
|
24
30
|
# end
|
25
31
|
#
|
32
|
+
# or
|
33
|
+
#
|
34
|
+
# p = Oj::Parser.new(:saj)
|
35
|
+
# p.handler = MySaj.new()
|
36
|
+
# File.open('any.json', 'r') do |f|
|
37
|
+
# p.parse(f.read)
|
38
|
+
# end
|
39
|
+
#
|
26
40
|
# To make the desired methods active while parsing the desired method should
|
27
41
|
# be made public in the subclasses. If the methods remain private they will
|
28
42
|
# not be called during parsing.
|
@@ -61,6 +75,6 @@ module Oj
|
|
61
75
|
|
62
76
|
def error(message, line, column)
|
63
77
|
end
|
64
|
-
|
78
|
+
|
65
79
|
end # Saj
|
66
80
|
end # Oj
|
data/lib/oj/schandler.rb
CHANGED
@@ -64,13 +64,14 @@ module Oj
|
|
64
64
|
#
|
65
65
|
# hash_end
|
66
66
|
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
# the key-value pair that follows.
|
67
|
+
# At the end of a JSON object element the hash_end() callback is called if
|
68
|
+
# public.
|
70
69
|
#
|
71
70
|
# hash_key
|
72
71
|
#
|
73
|
-
#
|
72
|
+
# When a hash key is encountered the hash_key() method is called with the
|
73
|
+
# parsed hash value key. The return value from the call is then used as the
|
74
|
+
# key in the key-value pair that follows.
|
74
75
|
#
|
75
76
|
# hash_set
|
76
77
|
#
|
data/lib/oj/state.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
|
2
1
|
module JSON
|
3
2
|
module Ext
|
4
|
-
module Generator
|
3
|
+
module Generator
|
5
4
|
unless defined?(::JSON::Ext::Generator::State)
|
6
5
|
# This class exists for json gem compatibility only. While it can be
|
7
6
|
# used as the options for other than compatibility a simple Hash is
|
@@ -44,11 +43,11 @@ module JSON
|
|
44
43
|
def to_h()
|
45
44
|
return @attrs.dup
|
46
45
|
end
|
47
|
-
|
46
|
+
|
48
47
|
def to_hash()
|
49
48
|
return @attrs.dup
|
50
49
|
end
|
51
|
-
|
50
|
+
|
52
51
|
def allow_nan?()
|
53
52
|
@attrs[:allow_nan]
|
54
53
|
end
|
@@ -59,6 +58,7 @@ module JSON
|
|
59
58
|
|
60
59
|
def configure(opts)
|
61
60
|
raise TypeError.new('expected a Hash') unless opts.respond_to?(:to_h)
|
61
|
+
|
62
62
|
@attrs.merge!(opts.to_h)
|
63
63
|
end
|
64
64
|
|
@@ -80,10 +80,11 @@ module JSON
|
|
80
80
|
# @param [Symbol] m method symbol
|
81
81
|
# @return [Boolean] true for any method that matches an instance
|
82
82
|
# variable reader, otherwise false.
|
83
|
-
def respond_to?(m)
|
83
|
+
def respond_to?(m, include_all = false)
|
84
84
|
return true if super
|
85
85
|
return true if has_key?(key)
|
86
86
|
return true if has_key?(key.to_s)
|
87
|
+
|
87
88
|
has_key?(key.to_sym)
|
88
89
|
end
|
89
90
|
|
@@ -104,7 +105,7 @@ module JSON
|
|
104
105
|
def has_key?(k)
|
105
106
|
@attrs.has_key?(key.to_sym)
|
106
107
|
end
|
107
|
-
|
108
|
+
|
108
109
|
# Handles requests for Hash values. Others cause an Exception to be raised.
|
109
110
|
# @param [Symbol|String] m method symbol
|
110
111
|
# @return [Boolean] the value of the specified instance variable.
|
@@ -113,14 +114,17 @@ module JSON
|
|
113
114
|
def method_missing(m, *args, &block)
|
114
115
|
if m.to_s.end_with?('=')
|
115
116
|
raise ArgumentError.new("wrong number of arguments (#{args.size} for 1 with #{m}) to method #{m}") if args.nil? or 1 != args.length
|
117
|
+
|
116
118
|
m = m.to_s[0..-2]
|
117
119
|
m = m.to_sym
|
118
120
|
return @attrs.store(m, args[0])
|
119
|
-
|
121
|
+
end
|
122
|
+
if @attrs.has_key?(m.to_sym)
|
120
123
|
raise ArgumentError.new("wrong number of arguments (#{args.size} for 0 with #{m}) to method #{m}") unless args.nil? or args.empty?
|
124
|
+
|
121
125
|
return @attrs[m.to_sym]
|
122
126
|
end
|
123
|
-
|
127
|
+
return @attrs.send(m, *args, &block)
|
124
128
|
end
|
125
129
|
|
126
130
|
end # State
|
data/lib/oj/version.rb
CHANGED
data/lib/oj.rb
CHANGED
data/pages/Compatibility.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
**Ruby**
|
4
4
|
|
5
|
-
Oj is compatible with Ruby 2.
|
5
|
+
Oj is compatible with Ruby 2.4+ and RBX.
|
6
6
|
Support for JRuby has been removed as JRuby no longer supports C extensions and
|
7
7
|
there are bugs in the older versions that are not being fixed.
|
8
8
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Oj Install Options
|
2
|
+
|
3
|
+
### Enable trace log
|
4
|
+
|
5
|
+
```
|
6
|
+
$ gem install oj -- --enable-trace-log
|
7
|
+
```
|
8
|
+
|
9
|
+
To enable Oj trace feature, it uses `--enable-trace-log` option when installing the gem.
|
10
|
+
Then, the trace logs will be displayed when `:trace` option is set to `true`.
|
11
|
+
|
12
|
+
|
13
|
+
### Enable SIMD instructions
|
14
|
+
|
15
|
+
```
|
16
|
+
$ gem install oj -- --with-sse42
|
17
|
+
```
|
18
|
+
|
19
|
+
To enable the use of SIMD instructions in Oj, it uses the `--with-sse42` option when installing the gem.
|
20
|
+
This will enable the use of the SSE4.2 instructions in the internal.
|
data/pages/JsonGem.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
# JSON Quickstart
|
2
|
+
|
3
|
+
To have Oj universally "take over" many methods on the JSON constant (`load`, `parse`, etc.) with
|
4
|
+
their faster Oj counterparts, in a mode that is compatible with the json gem:
|
5
|
+
|
6
|
+
```ruby
|
7
|
+
Oj.mimic_JSON()
|
8
|
+
```
|
9
|
+
|
10
|
+
If the project does not already use the json gem, `JSON` will become available.
|
11
|
+
If the project does require the json gem, `Oj.mimic_JSON()` should be invoked after the
|
12
|
+
json gem has been required.
|
13
|
+
|
14
|
+
For more details and options, read on...
|
15
|
+
|
1
16
|
# Oj JSON Gem Compatibility
|
2
17
|
|
3
18
|
The `:compat` mode mimics the json gem. The json gem is built around the use
|
data/pages/Modes.md
CHANGED
@@ -39,7 +39,8 @@ if a non-native type is encountered instead of raising an Exception.
|
|
39
39
|
The `:compat` mode mimics the json gem. The json gem is built around the use
|
40
40
|
of the `to_json(*)` method defined for a class. Oj attempts to provide the
|
41
41
|
same functionality by being a drop in replacement with a few
|
42
|
-
exceptions.
|
42
|
+
exceptions. To universally replace many `JSON` methods with their faster Oj counterparts,
|
43
|
+
simply run `Oj.mimic_json`. [{file:JsonGem.md}](JsonGem.md) includes more details on
|
43
44
|
compatibility and use.
|
44
45
|
|
45
46
|
## :rails Mode
|
@@ -97,6 +98,8 @@ information.
|
|
97
98
|
| :bigdecimal_as_decimal | Boolean | | | | 3 | x | x | |
|
98
99
|
| :bigdecimal_load | Boolean | | | | | | x | |
|
99
100
|
| :compat_bigdecimal | Boolean | | | x | | | x | |
|
101
|
+
| :cache_keys | Boolean | x | x | x | x | | x | |
|
102
|
+
| :cache_strings | Fixnum | x | x | x | x | | x | |
|
100
103
|
| :circular | Boolean | x | x | x | x | x | x | |
|
101
104
|
| :class_cache | Boolean | | | | | x | x | |
|
102
105
|
| :create_additions | Boolean | | | x | x | | x | |
|
@@ -106,11 +109,11 @@ information.
|
|
106
109
|
| :float_precision | Fixnum | x | x | | | | x | |
|
107
110
|
| :hash_class | Class | | | x | x | | x | |
|
108
111
|
| :ignore | Array | | | | | x | x | |
|
109
|
-
| :indent | Integer | x | x |
|
112
|
+
| :indent | Integer | x | x | 4 | 4 | x | x | x |
|
110
113
|
| :indent_str | String | | | x | x | | x | |
|
111
114
|
| :integer_range | Range | x | x | x | x | x | x | x |
|
112
115
|
| :match_string | Hash | | | x | x | | x | |
|
113
|
-
| :max_nesting | Fixnum |
|
116
|
+
| :max_nesting | Fixnum | 5 | 5 | x | | 5 | 5 | |
|
114
117
|
| :mode | Symbol | - | - | - | - | - | - | |
|
115
118
|
| :nan | Symbol | | | | | | x | |
|
116
119
|
| :nilnil | Boolean | | | | | | x | |
|
@@ -138,6 +141,8 @@ information.
|
|
138
141
|
3. By default the bigdecimal_as decimal is not set and the default encoding
|
139
142
|
for Rails is as a string. Setting the value to true will encode a
|
140
143
|
BigDecimal as a number which breaks compatibility.
|
144
|
+
Note: after version 3.11.3 both `Oj.generate` and `JSON.generate`
|
145
|
+
will not honour this option in Rails Mode, detais on https://github.com/ohler55/oj/pull/716.
|
141
146
|
|
142
147
|
4. The integer indent value in the default options will be honored by since
|
143
148
|
the json gem expects a String type the indent in calls to 'to_json()',
|