oj 3.7.4 → 3.13.21
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/CHANGELOG.md +1352 -0
- data/README.md +29 -8
- data/RELEASE_NOTES.md +61 -0
- data/ext/oj/buf.h +53 -72
- data/ext/oj/cache.c +326 -0
- data/ext/oj/cache.h +21 -0
- data/ext/oj/cache8.c +61 -64
- data/ext/oj/cache8.h +12 -39
- data/ext/oj/circarray.c +37 -43
- data/ext/oj/circarray.h +16 -17
- data/ext/oj/code.c +165 -179
- data/ext/oj/code.h +27 -29
- data/ext/oj/compat.c +174 -194
- data/ext/oj/custom.c +809 -866
- data/ext/oj/debug.c +132 -0
- data/ext/oj/dump.c +848 -863
- data/ext/oj/dump.h +81 -67
- data/ext/oj/dump_compat.c +85 -123
- data/ext/oj/dump_leaf.c +100 -188
- data/ext/oj/dump_object.c +527 -656
- data/ext/oj/dump_strict.c +315 -338
- data/ext/oj/encode.h +7 -34
- data/ext/oj/encoder.c +43 -0
- data/ext/oj/err.c +40 -29
- data/ext/oj/err.h +48 -48
- data/ext/oj/extconf.rb +17 -4
- data/ext/oj/fast.c +1070 -1087
- data/ext/oj/intern.c +301 -0
- data/ext/oj/intern.h +26 -0
- data/ext/oj/mimic_json.c +469 -436
- data/ext/oj/object.c +525 -593
- data/ext/oj/odd.c +154 -138
- data/ext/oj/odd.h +37 -38
- data/ext/oj/oj.c +1325 -986
- data/ext/oj/oj.h +333 -316
- data/ext/oj/parse.c +1002 -846
- data/ext/oj/parse.h +92 -87
- data/ext/oj/parser.c +1557 -0
- data/ext/oj/parser.h +91 -0
- data/ext/oj/rails.c +888 -878
- data/ext/oj/rails.h +11 -14
- data/ext/oj/reader.c +141 -147
- data/ext/oj/reader.h +73 -89
- data/ext/oj/resolve.c +41 -62
- data/ext/oj/resolve.h +7 -9
- data/ext/oj/rxclass.c +71 -75
- data/ext/oj/rxclass.h +18 -19
- data/ext/oj/saj.c +443 -486
- data/ext/oj/saj2.c +602 -0
- data/ext/oj/scp.c +88 -113
- data/ext/oj/sparse.c +787 -709
- data/ext/oj/stream_writer.c +133 -159
- data/ext/oj/strict.c +127 -118
- data/ext/oj/string_writer.c +230 -249
- data/ext/oj/trace.c +34 -41
- data/ext/oj/trace.h +19 -19
- data/ext/oj/usual.c +1254 -0
- data/ext/oj/util.c +136 -0
- data/ext/oj/util.h +20 -0
- data/ext/oj/val_stack.c +59 -67
- data/ext/oj/val_stack.h +91 -129
- data/ext/oj/validate.c +46 -0
- data/ext/oj/wab.c +342 -353
- data/lib/oj/bag.rb +1 -0
- data/lib/oj/easy_hash.rb +5 -4
- data/lib/oj/error.rb +1 -1
- data/lib/oj/json.rb +1 -1
- data/lib/oj/mimic.rb +48 -14
- data/lib/oj/saj.rb +20 -6
- data/lib/oj/state.rb +8 -7
- data/lib/oj/version.rb +2 -2
- data/lib/oj.rb +0 -8
- data/pages/Compatibility.md +1 -1
- data/pages/JsonGem.md +15 -0
- data/pages/Modes.md +53 -46
- data/pages/Options.md +72 -11
- data/pages/Parser.md +309 -0
- data/pages/Rails.md +73 -22
- data/pages/Security.md +1 -1
- data/test/activerecord/result_test.rb +7 -2
- data/test/activesupport5/abstract_unit.rb +45 -0
- data/test/activesupport5/decoding_test.rb +68 -60
- data/test/activesupport5/encoding_test.rb +111 -96
- data/test/activesupport5/encoding_test_cases.rb +33 -25
- data/test/activesupport5/test_helper.rb +43 -21
- data/test/activesupport5/time_zone_test_helpers.rb +18 -3
- data/test/activesupport6/abstract_unit.rb +44 -0
- data/test/activesupport6/decoding_test.rb +133 -0
- data/test/activesupport6/encoding_test.rb +507 -0
- data/test/activesupport6/encoding_test_cases.rb +98 -0
- data/test/activesupport6/test_common.rb +17 -0
- data/test/activesupport6/test_helper.rb +163 -0
- data/test/activesupport6/time_zone_test_helpers.rb +39 -0
- data/test/activesupport7/abstract_unit.rb +49 -0
- data/test/activesupport7/decoding_test.rb +125 -0
- data/test/activesupport7/encoding_test.rb +486 -0
- data/test/activesupport7/encoding_test_cases.rb +104 -0
- data/test/activesupport7/time_zone_test_helpers.rb +47 -0
- data/test/bar.rb +6 -12
- data/test/baz.rb +16 -0
- data/test/bug.rb +16 -0
- data/test/foo.rb +69 -75
- data/test/helper.rb +16 -0
- data/test/json_gem/json_common_interface_test.rb +8 -3
- data/test/json_gem/json_generator_test.rb +18 -4
- data/test/json_gem/json_parser_test.rb +9 -0
- data/test/json_gem/test_helper.rb +12 -0
- data/test/mem.rb +33 -0
- data/test/perf.rb +1 -1
- data/test/perf_dump.rb +50 -0
- data/test/perf_once.rb +58 -0
- data/test/perf_parser.rb +189 -0
- data/test/perf_scp.rb +11 -10
- data/test/perf_strict.rb +17 -23
- data/test/prec.rb +23 -0
- data/test/sample_json.rb +1 -1
- data/test/test_compat.rb +46 -10
- data/test/test_custom.rb +147 -8
- data/test/test_fast.rb +62 -2
- data/test/test_file.rb +25 -2
- data/test/test_gc.rb +13 -0
- data/test/test_generate.rb +21 -0
- data/test/test_hash.rb +11 -1
- data/test/test_integer_range.rb +7 -2
- data/test/test_object.rb +85 -9
- data/test/test_parser.rb +27 -0
- data/test/test_parser_saj.rb +335 -0
- data/test/test_parser_usual.rb +217 -0
- data/test/test_rails.rb +35 -0
- data/test/test_saj.rb +1 -1
- data/test/test_scp.rb +5 -5
- data/test/test_strict.rb +26 -1
- data/test/test_various.rb +87 -65
- data/test/test_wab.rb +2 -0
- data/test/test_writer.rb +19 -2
- data/test/tests.rb +1 -1
- data/test/zoo.rb +13 -0
- metadata +60 -110
- data/ext/oj/hash.c +0 -163
- data/ext/oj/hash.h +0 -46
- data/ext/oj/hash_test.c +0 -512
data/lib/oj/bag.rb
CHANGED
data/lib/oj/easy_hash.rb
CHANGED
@@ -12,13 +12,14 @@ module Oj
|
|
12
12
|
|
13
13
|
# Replaces the Object.respond_to?() method.
|
14
14
|
# @param [Symbol] m method symbol
|
15
|
+
# @param [Boolean] include_all whether to include private and protected methods in the search
|
15
16
|
# @return [Boolean] true for any method that matches an instance
|
16
17
|
# variable reader, otherwise false.
|
17
|
-
def respond_to?(m)
|
18
|
+
def respond_to?(m, include_all = false)
|
18
19
|
return true if super
|
19
|
-
return true if has_key?(
|
20
|
-
return true if has_key?(
|
21
|
-
has_key?(
|
20
|
+
return true if has_key?(m)
|
21
|
+
return true if has_key?(m.to_s)
|
22
|
+
has_key?(m.to_sym)
|
22
23
|
end
|
23
24
|
|
24
25
|
def [](key)
|
data/lib/oj/error.rb
CHANGED
@@ -16,7 +16,7 @@ module Oj
|
|
16
16
|
# An Exception that is raised if a file fails to load.
|
17
17
|
LoadError = Class.new(Error)
|
18
18
|
|
19
|
-
# An Exception that is raised if there is a conflict with
|
19
|
+
# An Exception that is raised if there is a conflict with mimicking JSON
|
20
20
|
MimicError = Class.new(Error)
|
21
21
|
|
22
22
|
end # Oj
|
data/lib/oj/json.rb
CHANGED
data/lib/oj/mimic.rb
CHANGED
@@ -8,6 +8,52 @@ end
|
|
8
8
|
|
9
9
|
module Oj
|
10
10
|
|
11
|
+
##
|
12
|
+
# Custom mode can be used to emulate the compat mode with some minor
|
13
|
+
# differences. These are the options that setup the custom mode to be like
|
14
|
+
# the compat mode.
|
15
|
+
CUSTOM_MIMIC_JSON_OPTIONS = {
|
16
|
+
allow_gc: true,
|
17
|
+
allow_invalid_unicode: false,
|
18
|
+
allow_nan: false,
|
19
|
+
array_class: nil,
|
20
|
+
array_nl: nil,
|
21
|
+
auto_define: false,
|
22
|
+
bigdecimal_as_decimal: false,
|
23
|
+
bigdecimal_load: :auto,
|
24
|
+
circular: false,
|
25
|
+
class_cache: false,
|
26
|
+
cache_keys: true,
|
27
|
+
cache_str: 5,
|
28
|
+
create_additions: false,
|
29
|
+
create_id: "json_class",
|
30
|
+
empty_string: false,
|
31
|
+
escape_mode: :unicode_xss,
|
32
|
+
float_precision: 0,
|
33
|
+
hash_class: nil,
|
34
|
+
ignore: nil,
|
35
|
+
ignore_under: false,
|
36
|
+
indent: 0,
|
37
|
+
integer_range: nil,
|
38
|
+
mode: :custom,
|
39
|
+
nan: :raise,
|
40
|
+
nilnil: false,
|
41
|
+
object_nl: nil,
|
42
|
+
omit_nil: false,
|
43
|
+
quirks_mode: true,
|
44
|
+
safe: false,
|
45
|
+
second_precision: 3,
|
46
|
+
space: nil,
|
47
|
+
space_before: nil,
|
48
|
+
symbol_keys: false,
|
49
|
+
time_format: :ruby,
|
50
|
+
trace: false,
|
51
|
+
use_as_json: false,
|
52
|
+
use_raw_json: false,
|
53
|
+
use_to_hash: false,
|
54
|
+
use_to_json: true,
|
55
|
+
}
|
56
|
+
|
11
57
|
# A bit hack-ish but does the trick. The JSON.dump_default_options is a Hash
|
12
58
|
# but in mimic we use a C struct to store defaults. This class creates a view
|
13
59
|
# onto that struct.
|
@@ -31,14 +77,14 @@ module Oj
|
|
31
77
|
end
|
32
78
|
|
33
79
|
# Loads mimic-ed JSON paths. Used by Oj.mimic_JSON().
|
34
|
-
# @param
|
80
|
+
# @param mimic_paths [Array] additional paths to add to the Ruby loaded features.
|
35
81
|
def self.mimic_loaded(mimic_paths=[])
|
36
82
|
$LOAD_PATH.each do |d|
|
37
83
|
next unless File.exist?(d)
|
38
84
|
|
39
85
|
jfile = File.join(d, 'json.rb')
|
40
86
|
$LOADED_FEATURES << jfile unless $LOADED_FEATURES.include?(jfile) if File.exist?(jfile)
|
41
|
-
|
87
|
+
|
42
88
|
Dir.glob(File.join(d, 'json', '**', '*.rb')).each do |file|
|
43
89
|
# allow json/add/xxx to be loaded. User can override with Oj.add_to_json(xxx).
|
44
90
|
$LOADED_FEATURES << file unless $LOADED_FEATURES.include?(file) unless file.include?('add')
|
@@ -89,18 +135,6 @@ module Oj
|
|
89
135
|
end
|
90
136
|
end
|
91
137
|
|
92
|
-
Date.class_eval do
|
93
|
-
# Both the JSON gem and Rails monkey patch as_json. Let them battle it out.
|
94
|
-
unless defined?(self.as_json)
|
95
|
-
def as_json(*)
|
96
|
-
{ JSON.create_id => 'Date', 'y' => year, 'm' => month, 'd' => day, 'sg' => start }
|
97
|
-
end
|
98
|
-
end
|
99
|
-
def self.json_create(h)
|
100
|
-
civil(h['y'], h['m'], h['d'], h['sg'])
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
138
|
DateTime.class_eval do
|
105
139
|
# Both the JSON gem and Rails monkey patch as_json. Let them battle it out.
|
106
140
|
unless defined?(self.as_json)
|
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/state.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
module JSON
|
3
3
|
module Ext
|
4
|
-
module Generator
|
4
|
+
module Generator
|
5
5
|
unless defined?(::JSON::Ext::Generator::State)
|
6
6
|
# This class exists for json gem compatibility only. While it can be
|
7
7
|
# used as the options for other than compatibility a simple Hash is
|
@@ -44,11 +44,11 @@ module JSON
|
|
44
44
|
def to_h()
|
45
45
|
return @attrs.dup
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
def to_hash()
|
49
49
|
return @attrs.dup
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
def allow_nan?()
|
53
53
|
@attrs[:allow_nan]
|
54
54
|
end
|
@@ -104,7 +104,7 @@ module JSON
|
|
104
104
|
def has_key?(k)
|
105
105
|
@attrs.has_key?(key.to_sym)
|
106
106
|
end
|
107
|
-
|
107
|
+
|
108
108
|
# Handles requests for Hash values. Others cause an Exception to be raised.
|
109
109
|
# @param [Symbol|String] m method symbol
|
110
110
|
# @return [Boolean] the value of the specified instance variable.
|
@@ -116,11 +116,12 @@ module JSON
|
|
116
116
|
m = m.to_s[0..-2]
|
117
117
|
m = m.to_sym
|
118
118
|
return @attrs.store(m, args[0])
|
119
|
-
|
119
|
+
end
|
120
|
+
if @attrs.has_key?(m.to_sym)
|
120
121
|
raise ArgumentError.new("wrong number of arguments (#{args.size} for 0 with #{m}) to method #{m}") unless args.nil? or args.empty?
|
121
122
|
return @attrs[m.to_sym]
|
122
|
-
|
123
|
-
|
123
|
+
end
|
124
|
+
return @attrs.send(m, *args, &block)
|
124
125
|
end
|
125
126
|
|
126
127
|
end # State
|
data/lib/oj/version.rb
CHANGED
data/lib/oj.rb
CHANGED
@@ -2,14 +2,6 @@
|
|
2
2
|
module Oj
|
3
3
|
end
|
4
4
|
|
5
|
-
begin
|
6
|
-
# This require exists to get around Rubinius failing to load bigdecimal from
|
7
|
-
# the C extension.
|
8
|
-
require 'bigdecimal'
|
9
|
-
rescue Exception
|
10
|
-
# ignore
|
11
|
-
end
|
12
|
-
|
13
5
|
require 'oj/version'
|
14
6
|
require 'oj/bag'
|
15
7
|
require 'oj/easy_hash'
|
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
|
|
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
@@ -14,7 +14,7 @@ modes are:
|
|
14
14
|
- `:object`
|
15
15
|
- `:custom`
|
16
16
|
|
17
|
-
Since modes
|
17
|
+
Since modes determine what the JSON output will look like and alternatively
|
18
18
|
what Oj expects when the `Oj.load()` method is called, mixing the output and
|
19
19
|
input mode formats will most likely not behave as intended. If the object mode
|
20
20
|
is used for producing JSON then use object mode for reading. The same is true
|
@@ -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
|
@@ -84,49 +85,54 @@ options available in each mode. An `x` in the matrix indicates the option is
|
|
84
85
|
supported in that mode. A number indicates the footnotes describe additional
|
85
86
|
information.
|
86
87
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
88
|
+
| Option | type | :null | :strict | :compat | :rails | :object | :custom | :wab |
|
89
|
+
| ---------------------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- |
|
90
|
+
| :allow_blank | Boolean | | | 1 | 1 | | x | |
|
91
|
+
| :allow_gc | Boolean | x | x | x | x | x | x | |
|
92
|
+
| :allow_invalid_unicode | Boolean | | | | | x | x | |
|
93
|
+
| :allow_nan | Boolean | | | x | | x | x | |
|
94
|
+
| :array_class | Class | | | x | x | | x | |
|
95
|
+
| :array_nl | String | | | | | | x | |
|
96
|
+
| :ascii_only | Boolean | x | x | 2 | 2 | x | x | |
|
97
|
+
| :auto_define | Boolean | | | | | x | x | |
|
98
|
+
| :bigdecimal_as_decimal | Boolean | | | | 3 | x | x | |
|
99
|
+
| :bigdecimal_load | Boolean | | | | | | x | |
|
100
|
+
| :compat_bigdecimal | Boolean | | | x | | | x | |
|
101
|
+
| :cache_keys | Boolean | x | x | x | x | | x | |
|
102
|
+
| :cache_strings | Fixnum | x | x | x | x | | x | |
|
103
|
+
| :circular | Boolean | x | x | x | x | x | x | |
|
104
|
+
| :class_cache | Boolean | | | | | x | x | |
|
105
|
+
| :create_additions | Boolean | | | x | x | | x | |
|
106
|
+
| :create_id | String | | | x | x | | x | |
|
107
|
+
| :empty_string | Boolean | | | | | | x | |
|
108
|
+
| :escape_mode | Symbol | | | | | | x | |
|
109
|
+
| :float_precision | Fixnum | x | x | | | | x | |
|
110
|
+
| :hash_class | Class | | | x | x | | x | |
|
111
|
+
| :ignore | Array | | | | | x | x | |
|
112
|
+
| :indent | Integer | x | x | 4 | 4 | x | x | x |
|
113
|
+
| :indent_str | String | | | x | x | | x | |
|
114
|
+
| :integer_range | Range | x | x | x | x | x | x | x |
|
115
|
+
| :match_string | Hash | | | x | x | | x | |
|
116
|
+
| :max_nesting | Fixnum | 5 | 5 | x | | 5 | 5 | |
|
117
|
+
| :mode | Symbol | - | - | - | - | - | - | |
|
118
|
+
| :nan | Symbol | | | | | | x | |
|
119
|
+
| :nilnil | Boolean | | | | | | x | |
|
120
|
+
| :object_class | Class | | | x | | | x | |
|
121
|
+
| :object_nl | String | | | x | x | | x | |
|
122
|
+
| :omit_nil | Boolean | x | x | x | x | x | x | |
|
123
|
+
| :quirks_mode | Boolean | | | 6 | | | x | |
|
124
|
+
| :safe | String | | | x | | | | |
|
125
|
+
| :second_precision | Fixnum | | | | | x | x | |
|
126
|
+
| :space | String | | | x | x | | x | |
|
127
|
+
| :space_before | String | | | x | x | | x | |
|
128
|
+
| :symbol_keys | Boolean | x | x | x | x | x | x | |
|
129
|
+
| :trace | Boolean | x | x | x | x | x | x | x |
|
130
|
+
| :time_format | Symbol | | | | | x | x | |
|
131
|
+
| :use_as_json | Boolean | | | | | | x | |
|
132
|
+
| :use_raw_json | Boolean | | | x | x | x | x | |
|
133
|
+
| :use_to_hash | Boolean | | | | | | x | |
|
134
|
+
| :use_to_json | Boolean | | | | | | x | |
|
135
|
+
--------------------------------------------------------------------------------------------------------
|
130
136
|
|
131
137
|
1. :allow_blank an alias for :nilnil.
|
132
138
|
|
@@ -135,6 +141,8 @@ information.
|
|
135
141
|
3. By default the bigdecimal_as decimal is not set and the default encoding
|
136
142
|
for Rails is as a string. Setting the value to true will encode a
|
137
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.
|
138
146
|
|
139
147
|
4. The integer indent value in the default options will be honored by since
|
140
148
|
the json gem expects a String type the indent in calls to 'to_json()',
|
@@ -151,4 +159,3 @@ information.
|
|
151
159
|
6. The quirks mode option is no longer supported in the most recent json
|
152
160
|
gem. It is supported by Oj for backward compatibility with older json gem
|
153
161
|
versions.
|
154
|
-
|
data/pages/Options.md
CHANGED
@@ -66,6 +66,32 @@ Determines how to load decimals.
|
|
66
66
|
|
67
67
|
- `:auto` the most precise for the number of digits is used.
|
68
68
|
|
69
|
+
This can also be set with `:decimal_class` when used as a load or
|
70
|
+
parse option to match the JSON gem. In that case either `Float`,
|
71
|
+
`BigDecimal`, or `nil` can be provided.
|
72
|
+
|
73
|
+
### :cache_keys [Boolean]
|
74
|
+
|
75
|
+
If true Hash keys are cached or interned. There are trade-offs with
|
76
|
+
caching keys. Large caches will use more memory and in extreme cases
|
77
|
+
(like over a million) the cache may be slower than not using
|
78
|
+
it. Repeated parsing of similar JSON docs is where cache_keys shines
|
79
|
+
especially with symbol keys.
|
80
|
+
|
81
|
+
There is a maximum length for cached keys. Any key longer than 34
|
82
|
+
bytes is not cached. Everything still works but the key is not cached.
|
83
|
+
|
84
|
+
### :cache_strings [Int]
|
85
|
+
|
86
|
+
Shorter strings can be cached for better performance. A limit,
|
87
|
+
cache_strings, defines the upper limit on what strings are cached. As
|
88
|
+
with cached keys only strings less than 35 bytes are cached even if
|
89
|
+
the limit is set higher. Setting the limit to zero effectively
|
90
|
+
disables the caching of string values.
|
91
|
+
|
92
|
+
Note that caching for strings is for string values and not Hash keys
|
93
|
+
or Object attributes.
|
94
|
+
|
69
95
|
### :circular [Boolean]
|
70
96
|
|
71
97
|
Detect circular references while dumping. In :compat mode raise a
|
@@ -78,17 +104,29 @@ recreate the looped references on load.
|
|
78
104
|
Cache classes for faster parsing. This option should not be used if
|
79
105
|
dynamically modifying classes or reloading classes then don't use this.
|
80
106
|
|
107
|
+
### :compat_bigdecimal [Boolean]
|
108
|
+
|
109
|
+
Determines how to load decimals when in `:compat` mode.
|
110
|
+
|
111
|
+
- `true` convert all decimal numbers to BigDecimal.
|
112
|
+
|
113
|
+
- `false` convert all decimal numbers to Float.
|
114
|
+
|
81
115
|
### :create_additions
|
82
116
|
|
83
|
-
A flag indicating the :create_id key when encountered during parsing
|
84
|
-
|
85
|
-
with the key.
|
117
|
+
A flag indicating that the :create_id key, when encountered during parsing,
|
118
|
+
should create an Object matching the class name specified in the value
|
119
|
+
associated with the key.
|
86
120
|
|
87
121
|
### :create_id [String]
|
88
122
|
|
89
123
|
The :create_id option specifies that key is used for dumping and loading when
|
90
124
|
specifying the class for an encoded object. The default is `json_create`.
|
91
125
|
|
126
|
+
In the `:custom` mode, setting the `:create_id` to nil will cause Complex,
|
127
|
+
Rational, Range, and Regexp to be output as strings instead of as JSON
|
128
|
+
objects.
|
129
|
+
|
92
130
|
### :empty_string [Boolean]
|
93
131
|
|
94
132
|
If true an empty or all whitespace input will not raise an Exception. The
|
@@ -149,7 +187,7 @@ integer gives better performance.
|
|
149
187
|
|
150
188
|
### :integer_range [Range]
|
151
189
|
|
152
|
-
Dump integers outside range as strings.
|
190
|
+
Dump integers outside range as strings.
|
153
191
|
Note: range bounds must be Fixnum.
|
154
192
|
|
155
193
|
### :match_string
|
@@ -175,7 +213,7 @@ customization.
|
|
175
213
|
### :nan [Symbol]
|
176
214
|
|
177
215
|
How to dump Infinity, -Infinity, and NaN in :null, :strict, and :compat
|
178
|
-
mode. Default is :auto but is ignored in the :compat and :rails
|
216
|
+
mode. Default is :auto but is ignored in the :compat and :rails modes.
|
179
217
|
|
180
218
|
- `:null` places a null
|
181
219
|
|
@@ -211,6 +249,12 @@ Allow single JSON values instead of documents, default is true (allow). This
|
|
211
249
|
can also be used in :compat mode to be backward compatible with older versions
|
212
250
|
of the json gem.
|
213
251
|
|
252
|
+
### :safe
|
253
|
+
|
254
|
+
The JSON gem includes the complete JSON in parse errors with no limit
|
255
|
+
on size. To break from the JSON gem behavior for this case set `:safe`
|
256
|
+
to true.
|
257
|
+
|
214
258
|
### :second_precision [Fixnum]
|
215
259
|
|
216
260
|
The number of digits after the decimal when dumping the seconds of time.
|
@@ -229,7 +273,13 @@ compatibility. Using just indent as an integer gives better performance.
|
|
229
273
|
|
230
274
|
### :symbol_keys [Boolean]
|
231
275
|
|
232
|
-
Use symbols instead of strings for hash keys.
|
276
|
+
Use symbols instead of strings for hash keys.
|
277
|
+
|
278
|
+
### :symbolize_names [Boolean]
|
279
|
+
|
280
|
+
Like :symbol_keys has keys are made into symbols but only when
|
281
|
+
mimicking the JSON gem and then only as the JSON gem honors it so
|
282
|
+
JSON.parse honors the option but JSON.load does not.
|
233
283
|
|
234
284
|
### :trace
|
235
285
|
|
@@ -242,7 +292,7 @@ The :time_format when dumping.
|
|
242
292
|
|
243
293
|
- `:unix` time is output as a decimal number in seconds since epoch including fractions of a second.
|
244
294
|
|
245
|
-
- `:unix_zone` similar to the `:unix` format but with the timezone encoded in
|
295
|
+
- `:unix_zone` is similar to the `:unix` format but with the timezone encoded in
|
246
296
|
the exponent of the decimal number of seconds since epoch.
|
247
297
|
|
248
298
|
- `:xmlschema` time is output as a string that follows the XML schema definition.
|
@@ -252,15 +302,26 @@ The :time_format when dumping.
|
|
252
302
|
### :use_as_json [Boolean]
|
253
303
|
|
254
304
|
Call `as_json()` methods on dump, default is false. The option is ignored in
|
255
|
-
the :compat and :rails
|
305
|
+
the :compat and :rails modes.
|
306
|
+
|
307
|
+
|
308
|
+
### :use_raw_json [Boolean]
|
309
|
+
|
310
|
+
Call `raw_json()` methods on dump, default is false. The option is
|
311
|
+
accepted in the :compat and :rails modes even though it is not
|
312
|
+
supported by other JSON gems. It provides a means to optimize dump or
|
313
|
+
generate performance. The `raw_json(depth, indent)` method should be
|
314
|
+
called only by Oj. It is not intended for any other use. This is meant
|
315
|
+
to replace the abused `to_json` methods. Calling `Oj.dump` inside the
|
316
|
+
`raw_json` with the object itself when `:use_raw_json` is true will
|
317
|
+
result in an infinite loop.
|
256
318
|
|
257
319
|
### :use_to_hash [Boolean]
|
258
320
|
|
259
321
|
Call `to_hash()` methods on dump, default is false. The option is ignored in
|
260
|
-
the :compat and :rails
|
322
|
+
the :compat and :rails modes.
|
261
323
|
|
262
324
|
### :use_to_json [Boolean]
|
263
325
|
|
264
326
|
Call `to_json()` methods on dump, default is false. The option is ignored in
|
265
|
-
the :compat and :rails
|
266
|
-
|
327
|
+
the :compat and :rails modes.
|