oj 3.7.4 → 3.13.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1360 -0
  3. data/README.md +31 -8
  4. data/RELEASE_NOTES.md +61 -0
  5. data/ext/oj/buf.h +53 -72
  6. data/ext/oj/cache.c +326 -0
  7. data/ext/oj/cache.h +21 -0
  8. data/ext/oj/cache8.c +61 -64
  9. data/ext/oj/cache8.h +12 -39
  10. data/ext/oj/circarray.c +37 -43
  11. data/ext/oj/circarray.h +16 -17
  12. data/ext/oj/code.c +165 -179
  13. data/ext/oj/code.h +27 -29
  14. data/ext/oj/compat.c +174 -194
  15. data/ext/oj/custom.c +790 -866
  16. data/ext/oj/debug.c +132 -0
  17. data/ext/oj/dump.c +848 -863
  18. data/ext/oj/dump.h +81 -67
  19. data/ext/oj/dump_compat.c +85 -123
  20. data/ext/oj/dump_leaf.c +100 -188
  21. data/ext/oj/dump_object.c +527 -656
  22. data/ext/oj/dump_strict.c +315 -338
  23. data/ext/oj/encode.h +7 -34
  24. data/ext/oj/encoder.c +43 -0
  25. data/ext/oj/err.c +40 -29
  26. data/ext/oj/err.h +48 -48
  27. data/ext/oj/extconf.rb +17 -4
  28. data/ext/oj/fast.c +1073 -1088
  29. data/ext/oj/intern.c +298 -0
  30. data/ext/oj/intern.h +26 -0
  31. data/ext/oj/mimic_json.c +469 -436
  32. data/ext/oj/object.c +532 -599
  33. data/ext/oj/odd.c +154 -138
  34. data/ext/oj/odd.h +37 -38
  35. data/ext/oj/oj.c +1333 -986
  36. data/ext/oj/oj.h +336 -316
  37. data/ext/oj/parse.c +1002 -846
  38. data/ext/oj/parse.h +92 -87
  39. data/ext/oj/parser.c +1587 -0
  40. data/ext/oj/parser.h +102 -0
  41. data/ext/oj/rails.c +888 -878
  42. data/ext/oj/rails.h +11 -14
  43. data/ext/oj/reader.c +141 -147
  44. data/ext/oj/reader.h +73 -89
  45. data/ext/oj/resolve.c +41 -62
  46. data/ext/oj/resolve.h +7 -9
  47. data/ext/oj/rxclass.c +71 -75
  48. data/ext/oj/rxclass.h +18 -19
  49. data/ext/oj/saj.c +443 -486
  50. data/ext/oj/saj2.c +596 -0
  51. data/ext/oj/saj2.h +23 -0
  52. data/ext/oj/scp.c +88 -113
  53. data/ext/oj/sparse.c +787 -709
  54. data/ext/oj/stream_writer.c +133 -159
  55. data/ext/oj/strict.c +127 -118
  56. data/ext/oj/string_writer.c +230 -249
  57. data/ext/oj/trace.c +34 -41
  58. data/ext/oj/trace.h +19 -19
  59. data/ext/oj/usual.c +1207 -0
  60. data/ext/oj/usual.h +68 -0
  61. data/ext/oj/util.c +136 -0
  62. data/ext/oj/util.h +20 -0
  63. data/ext/oj/val_stack.c +60 -68
  64. data/ext/oj/val_stack.h +91 -129
  65. data/ext/oj/validate.c +46 -0
  66. data/ext/oj/wab.c +342 -353
  67. data/lib/oj/bag.rb +1 -0
  68. data/lib/oj/easy_hash.rb +5 -4
  69. data/lib/oj/error.rb +1 -1
  70. data/lib/oj/json.rb +1 -1
  71. data/lib/oj/mimic.rb +48 -14
  72. data/lib/oj/saj.rb +20 -6
  73. data/lib/oj/state.rb +9 -8
  74. data/lib/oj/version.rb +2 -2
  75. data/lib/oj.rb +0 -8
  76. data/pages/Compatibility.md +1 -1
  77. data/pages/JsonGem.md +15 -0
  78. data/pages/Modes.md +53 -46
  79. data/pages/Options.md +78 -11
  80. data/pages/Parser.md +309 -0
  81. data/pages/Rails.md +73 -22
  82. data/pages/Security.md +1 -1
  83. data/test/activerecord/result_test.rb +7 -2
  84. data/test/activesupport5/abstract_unit.rb +45 -0
  85. data/test/activesupport5/decoding_test.rb +68 -60
  86. data/test/activesupport5/encoding_test.rb +111 -96
  87. data/test/activesupport5/encoding_test_cases.rb +33 -25
  88. data/test/activesupport5/test_helper.rb +43 -21
  89. data/test/activesupport5/time_zone_test_helpers.rb +18 -3
  90. data/test/activesupport6/abstract_unit.rb +44 -0
  91. data/test/activesupport6/decoding_test.rb +133 -0
  92. data/test/activesupport6/encoding_test.rb +507 -0
  93. data/test/activesupport6/encoding_test_cases.rb +98 -0
  94. data/test/activesupport6/test_common.rb +17 -0
  95. data/test/activesupport6/test_helper.rb +163 -0
  96. data/test/activesupport6/time_zone_test_helpers.rb +39 -0
  97. data/test/activesupport7/abstract_unit.rb +49 -0
  98. data/test/activesupport7/decoding_test.rb +125 -0
  99. data/test/activesupport7/encoding_test.rb +486 -0
  100. data/test/activesupport7/encoding_test_cases.rb +104 -0
  101. data/test/activesupport7/time_zone_test_helpers.rb +47 -0
  102. data/test/bar.rb +6 -12
  103. data/test/baz.rb +16 -0
  104. data/test/bug.rb +16 -0
  105. data/test/foo.rb +69 -75
  106. data/test/helper.rb +16 -0
  107. data/test/json_gem/json_common_interface_test.rb +8 -3
  108. data/test/json_gem/json_generator_test.rb +21 -8
  109. data/test/json_gem/json_parser_test.rb +8 -1
  110. data/test/json_gem/test_helper.rb +12 -0
  111. data/test/mem.rb +33 -0
  112. data/test/perf.rb +1 -1
  113. data/test/perf_dump.rb +50 -0
  114. data/test/perf_once.rb +58 -0
  115. data/test/perf_parser.rb +189 -0
  116. data/test/perf_scp.rb +11 -10
  117. data/test/perf_strict.rb +17 -23
  118. data/test/prec.rb +23 -0
  119. data/test/sample_json.rb +1 -1
  120. data/test/test_compat.rb +46 -10
  121. data/test/test_custom.rb +145 -7
  122. data/test/test_fast.rb +62 -2
  123. data/test/test_file.rb +23 -7
  124. data/test/test_gc.rb +11 -0
  125. data/test/test_generate.rb +21 -0
  126. data/test/test_hash.rb +11 -1
  127. data/test/test_integer_range.rb +1 -2
  128. data/test/test_object.rb +43 -12
  129. data/test/test_parser.rb +11 -0
  130. data/test/test_parser_debug.rb +27 -0
  131. data/test/test_parser_saj.rb +335 -0
  132. data/test/test_parser_usual.rb +217 -0
  133. data/test/test_rails.rb +35 -0
  134. data/test/test_saj.rb +1 -1
  135. data/test/test_scp.rb +3 -5
  136. data/test/test_strict.rb +26 -1
  137. data/test/test_various.rb +86 -65
  138. data/test/test_wab.rb +2 -0
  139. data/test/test_writer.rb +19 -2
  140. data/test/tests.rb +10 -1
  141. data/test/tests_mimic.rb +9 -0
  142. data/test/tests_mimic_addition.rb +9 -0
  143. data/test/zoo.rb +13 -0
  144. metadata +63 -110
  145. data/ext/oj/hash.c +0 -163
  146. data/ext/oj/hash.h +0 -46
  147. data/ext/oj/hash_test.c +0 -512
data/lib/oj/bag.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module Oj
3
4
 
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?(key)
20
- return true if has_key?(key.to_s)
21
- has_key?(key.to_sym)
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 mimicing JSON
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
@@ -95,7 +95,7 @@ module JSON
95
95
  State = ::JSON::Ext::Generator::State unless defined?(::JSON::State)
96
96
 
97
97
  begin
98
- Object.send(:remove_const, :Parser)
98
+ send(:remove_const, :Parser)
99
99
  rescue
100
100
  end
101
101
  Parser = ::JSON::Ext::Parser unless defined?(::JSON::Parser)
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 mimic_path [Array] additional paths to add to the Ruby loaded features.
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 for
3
- # JSON. The Oj::Saj handler class should be subclassed and then used with the
4
- # Oj::Saj key_parse() method. The Saj methods will then be called as the file
5
- # is parsed.
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
@@ -80,7 +80,7 @@ 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)
@@ -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
- else
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
- end
123
- raise NoMethodError.new("undefined method #{m}", m)
123
+ end
124
+ return @attrs.send(m, *args, &block)
124
125
  end
125
126
 
126
127
  end # State
data/lib/oj/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
- # Current version of the module.
4
- VERSION = '3.7.4'
3
+ # Current version of the module.
4
+ VERSION = '3.13.23'
5
5
  end
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'
@@ -2,7 +2,7 @@
2
2
 
3
3
  **Ruby**
4
4
 
5
- Oj is compatible with Ruby 2.0.0, 2.1, 2.2, 2.3, 2.4 and RBX.
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 detemine what the JSON output will look like and alternatively
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. [{file:JsonGem.md}](JsonGem.md) includes more details on
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
- | Option | type | :null | :strict | :compat | :rails | :object | :custom | :wab |
88
- | ---------------------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- |
89
- | :allow_blank | Boolean | | | 1 | 1 | | x | |
90
- | :allow_gc | Boolean | x | x | x | x | x | x | |
91
- | :allow_invalid_unicode | Boolean | | | | | x | x | |
92
- | :allow_nan | Boolean | | | x | | x | x | |
93
- | :array_class | Class | | | x | x | | x | |
94
- | :array_nl | String | | | | | | x | |
95
- | :ascii_only | Boolean | x | x | 2 | 2 | x | x | |
96
- | :auto_define | Boolean | | | | | x | x | |
97
- | :bigdecimal_as_decimal | Boolean | | | | 3 | x | x | |
98
- | :bigdecimal_load | Boolean | | | | | | x | |
99
- | :circular | Boolean | x | x | x | x | x | x | |
100
- | :class_cache | Boolean | | | | | x | x | |
101
- | :create_additions | Boolean | | | x | x | | x | |
102
- | :create_id | String | | | x | x | | x | |
103
- | :empty_string | Boolean | | | | | | x | |
104
- | :escape_mode | Symbol | | | | | | x | |
105
- | :float_precision | Fixnum | x | x | | | | x | |
106
- | :hash_class | Class | | | x | x | | x | |
107
- | :ignore | Array | | | | | x | x | |
108
- | :indent | Integer | x | x | 3 | 4 | x | x | x |
109
- | :indent_str | String | | | x | x | | x | |
110
- | :integer_range | Range | x | x | x | x | x | x | x |
111
- | :match_string | Hash | | | x | x | | x | |
112
- | :max_nesting | Fixnum | 4 | 4 | x | | 5 | 4 | |
113
- | :mode | Symbol | - | - | - | - | - | - | |
114
- | :nan | Symbol | | | | | | x | |
115
- | :nilnil | Boolean | | | | | | x | |
116
- | :object_class | Class | | | x | | | x | |
117
- | :object_nl | String | | | x | x | | x | |
118
- | :omit_nil | Boolean | x | x | x | x | x | x | |
119
- | :quirks_mode | Boolean | | | 6 | | | x | |
120
- | :second_precision | Fixnum | | | | | x | x | |
121
- | :space | String | | | x | x | | x | |
122
- | :space_before | String | | | x | x | | x | |
123
- | :symbol_keys | Boolean | x | x | x | x | x | x | |
124
- | :trace | Boolean | x | x | x | x | x | x | x |
125
- | :time_format | Symbol | | | | | x | x | |
126
- | :use_as_json | Boolean | | | | | | x | |
127
- | :use_to_hash | Boolean | | | | | | x | |
128
- | :use_to_json | Boolean | | | | | | x | |
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,36 @@ Determines how to load decimals.
66
66
 
67
67
  - `:auto` the most precise for the number of digits is used.
68
68
 
69
+ - `:fast` faster conversion to Float.
70
+
71
+ - `:ruby` convert to Float using the Ruby `to_f` conversion.
72
+
73
+ This can also be set with `:decimal_class` when used as a load or
74
+ parse option to match the JSON gem. In that case either `Float`,
75
+ `BigDecimal`, or `nil` can be provided.
76
+
77
+ ### :cache_keys [Boolean]
78
+
79
+ If true Hash keys are cached or interned. There are trade-offs with
80
+ caching keys. Large caches will use more memory and in extreme cases
81
+ (like over a million) the cache may be slower than not using
82
+ it. Repeated parsing of similar JSON docs is where cache_keys shines
83
+ especially with symbol keys.
84
+
85
+ There is a maximum length for cached keys. Any key longer than 34
86
+ bytes is not cached. Everything still works but the key is not cached.
87
+
88
+ ### :cache_strings [Int]
89
+
90
+ Shorter strings can be cached for better performance. A limit,
91
+ cache_strings, defines the upper limit on what strings are cached. As
92
+ with cached keys only strings less than 35 bytes are cached even if
93
+ the limit is set higher. Setting the limit to zero effectively
94
+ disables the caching of string values.
95
+
96
+ Note that caching for strings is for string values and not Hash keys
97
+ or Object attributes.
98
+
69
99
  ### :circular [Boolean]
70
100
 
71
101
  Detect circular references while dumping. In :compat mode raise a
@@ -78,17 +108,29 @@ recreate the looped references on load.
78
108
  Cache classes for faster parsing. This option should not be used if
79
109
  dynamically modifying classes or reloading classes then don't use this.
80
110
 
111
+ ### :compat_bigdecimal [Boolean]
112
+
113
+ Determines how to load decimals when in `:compat` mode.
114
+
115
+ - `true` convert all decimal numbers to BigDecimal.
116
+
117
+ - `false` convert all decimal numbers to Float.
118
+
81
119
  ### :create_additions
82
120
 
83
- A flag indicating the :create_id key when encountered during parsing should
84
- creating an Object mactching the class name specified in the value associated
85
- with the key.
121
+ A flag indicating that the :create_id key, when encountered during parsing,
122
+ should create an Object matching the class name specified in the value
123
+ associated with the key.
86
124
 
87
125
  ### :create_id [String]
88
126
 
89
127
  The :create_id option specifies that key is used for dumping and loading when
90
128
  specifying the class for an encoded object. The default is `json_create`.
91
129
 
130
+ In the `:custom` mode, setting the `:create_id` to nil will cause Complex,
131
+ Rational, Range, and Regexp to be output as strings instead of as JSON
132
+ objects.
133
+
92
134
  ### :empty_string [Boolean]
93
135
 
94
136
  If true an empty or all whitespace input will not raise an Exception. The
@@ -116,6 +158,8 @@ Determines the characters to escape when dumping. Only the :ascii and
116
158
 
117
159
  - `:json` follows the JSON specification. This is the default mode.
118
160
 
161
+ - `:slash` escapes `/` characters.
162
+
119
163
  - `:xss_safe` escapes HTML and XML characters such as `&` and `<`.
120
164
 
121
165
  - `:ascii` escapes all non-ascii or characters with the hi-bit set.
@@ -149,7 +193,7 @@ integer gives better performance.
149
193
 
150
194
  ### :integer_range [Range]
151
195
 
152
- Dump integers outside range as strings.
196
+ Dump integers outside range as strings.
153
197
  Note: range bounds must be Fixnum.
154
198
 
155
199
  ### :match_string
@@ -175,7 +219,7 @@ customization.
175
219
  ### :nan [Symbol]
176
220
 
177
221
  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 mode.
222
+ mode. Default is :auto but is ignored in the :compat and :rails modes.
179
223
 
180
224
  - `:null` places a null
181
225
 
@@ -211,6 +255,12 @@ Allow single JSON values instead of documents, default is true (allow). This
211
255
  can also be used in :compat mode to be backward compatible with older versions
212
256
  of the json gem.
213
257
 
258
+ ### :safe
259
+
260
+ The JSON gem includes the complete JSON in parse errors with no limit
261
+ on size. To break from the JSON gem behavior for this case set `:safe`
262
+ to true.
263
+
214
264
  ### :second_precision [Fixnum]
215
265
 
216
266
  The number of digits after the decimal when dumping the seconds of time.
@@ -229,7 +279,13 @@ compatibility. Using just indent as an integer gives better performance.
229
279
 
230
280
  ### :symbol_keys [Boolean]
231
281
 
232
- Use symbols instead of strings for hash keys. :symbolize_names is an alias.
282
+ Use symbols instead of strings for hash keys.
283
+
284
+ ### :symbolize_names [Boolean]
285
+
286
+ Like :symbol_keys has keys are made into symbols but only when
287
+ mimicking the JSON gem and then only as the JSON gem honors it so
288
+ JSON.parse honors the option but JSON.load does not.
233
289
 
234
290
  ### :trace
235
291
 
@@ -242,7 +298,7 @@ The :time_format when dumping.
242
298
 
243
299
  - `:unix` time is output as a decimal number in seconds since epoch including fractions of a second.
244
300
 
245
- - `:unix_zone` similar to the `:unix` format but with the timezone encoded in
301
+ - `:unix_zone` is similar to the `:unix` format but with the timezone encoded in
246
302
  the exponent of the decimal number of seconds since epoch.
247
303
 
248
304
  - `:xmlschema` time is output as a string that follows the XML schema definition.
@@ -252,15 +308,26 @@ The :time_format when dumping.
252
308
  ### :use_as_json [Boolean]
253
309
 
254
310
  Call `as_json()` methods on dump, default is false. The option is ignored in
255
- the :compat and :rails mode.
311
+ the :compat and :rails modes.
312
+
313
+
314
+ ### :use_raw_json [Boolean]
315
+
316
+ Call `raw_json()` methods on dump, default is false. The option is
317
+ accepted in the :compat and :rails modes even though it is not
318
+ supported by other JSON gems. It provides a means to optimize dump or
319
+ generate performance. The `raw_json(depth, indent)` method should be
320
+ called only by Oj. It is not intended for any other use. This is meant
321
+ to replace the abused `to_json` methods. Calling `Oj.dump` inside the
322
+ `raw_json` with the object itself when `:use_raw_json` is true will
323
+ result in an infinite loop.
256
324
 
257
325
  ### :use_to_hash [Boolean]
258
326
 
259
327
  Call `to_hash()` methods on dump, default is false. The option is ignored in
260
- the :compat and :rails mode.
328
+ the :compat and :rails modes.
261
329
 
262
330
  ### :use_to_json [Boolean]
263
331
 
264
332
  Call `to_json()` methods on dump, default is false. The option is ignored in
265
- the :compat and :rails mode.
266
-
333
+ the :compat and :rails modes.